| 1: | <?php | 
| 2: |  | 
| 3: |  | 
| 4: |  | 
| 5: |  | 
| 6: |  | 
| 7: |  | 
| 8: |  | 
| 9: |  | 
| 10: |  | 
| 11: |  | 
| 12: |  | 
| 13: |  | 
| 14: |  | 
| 15: |  | 
| 16: |  | 
| 17: |  | 
| 18: |  | 
| 19: | use Xmf\Request; | 
| 20: |  | 
| 21: | if (!is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid())) { | 
| 22: | exit(_NOPERM); | 
| 23: | } | 
| 24: |  | 
| 25: |  | 
| 26: | if (!xoops_getModuleOption('active_users', 'system')) { | 
| 27: | redirect_header('admin.php', 2, _AM_SYSTEM_NOTACTIVE); | 
| 28: | } | 
| 29: |  | 
| 30: |  | 
| 31: |  | 
| 32: |  | 
| 33: | include_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; | 
| 34: | include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; | 
| 35: |  | 
| 36: |  | 
| 37: |  | 
| 38: |  | 
| 39: |  | 
| 40: |  | 
| 41: |  | 
| 42: | function form_user($add_or_edit, $user = '') | 
| 43: | { | 
| 44: | global $xoopsConfig, $xoopsUser; | 
| 45: | $uid = Request::getInt('uid', 0); | 
| 46: |  | 
| 47: |  | 
| 48: | include_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/notification.php'; | 
| 49: | include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; | 
| 50: |  | 
| 51: | if ($add_or_edit === true) { | 
| 52: |  | 
| 53: | $config_handler  = xoops_getHandler('config'); | 
| 54: | $xoopsConfigUser = $config_handler->getConfigsByCat(XOOPS_CONF_USER); | 
| 55: |  | 
| 56: | $uid_value        = ''; | 
| 57: | $uname_value      = ''; | 
| 58: | $name_value       = ''; | 
| 59: | $email_value      = ''; | 
| 60: | $email_cbox_value = 0; | 
| 61: | $url_value        = ''; | 
| 62: | $timezone_value   = $xoopsConfig['default_TZ']; | 
| 63: | $icq_value        = ''; | 
| 64: | $aim_value        = ''; | 
| 65: | $yim_value        = ''; | 
| 66: | $msnm_value       = ''; | 
| 67: | $location_value   = ''; | 
| 68: | $occ_value        = ''; | 
| 69: | $interest_value   = ''; | 
| 70: | $sig_value        = ''; | 
| 71: | $sig_cbox_value   = 0; | 
| 72: | $umode_value      = $xoopsConfig['com_mode']; | 
| 73: | $uorder_value     = $xoopsConfig['com_order']; | 
| 74: |  | 
| 75: | $notify_method_value = (isset($xoopsConfigUser['default_notification']) ? $xoopsConfigUser['default_notification'] : XOOPS_NOTIFICATION_METHOD_PM); | 
| 76: | $notify_mode_value   = XOOPS_NOTIFICATION_MODE_SENDALWAYS; | 
| 77: | $bio_value           = ''; | 
| 78: | $rank_value          = 0; | 
| 79: | $mailok_value        = 0; | 
| 80: | $form_title          = _AM_SYSTEM_USERS_ADDUSER; | 
| 81: | $form_isedit         = false; | 
| 82: | $groups              = array(XOOPS_GROUP_USERS); | 
| 83: | } else { | 
| 84: |  | 
| 85: |  | 
| 86: | $member_handler = xoops_getHandler('member'); | 
| 87: | $user           = $member_handler->getUser($uid); | 
| 88: | if (is_object($user)) { | 
| 89: | $uid_value        = $uid; | 
| 90: | $uname_value      = $user->getVar('uname', 'E'); | 
| 91: | $name_value       = $user->getVar('name', 'E'); | 
| 92: | $email_value      = $user->getVar('email', 'E'); | 
| 93: | $email_cbox_value = $user->getVar('user_viewemail') ? 1 : 0; | 
| 94: | $url_value        = $user->getVar('url', 'E'); | 
| 95: | $temp             = $user->getVar('theme'); | 
| 96: | $timezone_value   = $user->getVar('timezone_offset'); | 
| 97: | $icq_value        = $user->getVar('user_icq', 'E'); | 
| 98: | $aim_value        = $user->getVar('user_aim', 'E'); | 
| 99: | $yim_value        = $user->getVar('user_yim', 'E'); | 
| 100: | $msnm_value       = $user->getVar('user_msnm', 'E'); | 
| 101: | $location_value   = $user->getVar('user_from', 'E'); | 
| 102: | $occ_value        = $user->getVar('user_occ', 'E'); | 
| 103: | $interest_value   = $user->getVar('user_intrest', 'E'); | 
| 104: | $sig_value        = $user->getVar('user_sig', 'E'); | 
| 105: | $sig_cbox_value   = ($user->getVar('attachsig') == 1) ? 1 : 0; | 
| 106: | $umode_value      = $user->getVar('umode'); | 
| 107: | $uorder_value     = $user->getVar('uorder'); | 
| 108: |  | 
| 109: | $notify_method_value = $user->getVar('notify_method'); | 
| 110: | $notify_mode_value   = $user->getVar('notify_mode'); | 
| 111: | $bio_value           = $user->getVar('bio', 'E'); | 
| 112: | $rank_value          = $user->rank(false); | 
| 113: | $mailok_value        = $user->getVar('user_mailok', 'E'); | 
| 114: | $form_title          = _AM_SYSTEM_USERS_UPDATEUSER . ': ' . $user->getVar('uname'); | 
| 115: | $form_isedit         = true; | 
| 116: | $groups              = array_values($user->getGroups()); | 
| 117: | } | 
| 118: | } | 
| 119: |  | 
| 120: |  | 
| 121: | $form = new XoopsThemeForm($form_title, 'form_user', 'admin.php', 'post', true); | 
| 122: |  | 
| 123: | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_NICKNAME, 'username', 25, 25, $uname_value), true); | 
| 124: | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_NAME, 'name', 30, 60, $name_value)); | 
| 125: | $email_tray = new XoopsFormElementTray(_AM_SYSTEM_USERS_EMAIL, '<br>'); | 
| 126: | $email_text = new XoopsFormText('', 'email', 30, 60, $email_value); | 
| 127: | $email_tray->addElement($email_text, true); | 
| 128: | $email_cbox = new XoopsFormCheckBox('', 'user_viewemail', $email_cbox_value); | 
| 129: | $email_cbox->addOption(1, _AM_SYSTEM_USERS_AOUTVTEAD); | 
| 130: | $email_tray->addElement($email_cbox); | 
| 131: | $form->addElement($email_tray, true); | 
| 132: | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_URL, 'url', 30, 100, $url_value)); | 
| 133: | $form->addElement(new XoopsFormSelectTimezone(_AM_SYSTEM_USERS_TIMEZONE, 'timezone_offset', $timezone_value)); | 
| 134: | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_ICQ, 'user_icq', 15, 15, $icq_value)); | 
| 135: | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_AIM, 'user_aim', 18, 18, $aim_value)); | 
| 136: | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_YIM, 'user_yim', 25, 25, $yim_value)); | 
| 137: | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_MSNM, 'user_msnm', 30, 100, $msnm_value)); | 
| 138: | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_LOCATION, 'user_from', 30, 100, $location_value)); | 
| 139: | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_OCCUPATION, 'user_occ', 30, 100, $occ_value)); | 
| 140: | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_INTEREST, 'user_intrest', 30, 150, $interest_value)); | 
| 141: | $sig_tray  = new XoopsFormElementTray(_AM_SYSTEM_USERS_SIGNATURE, '<br>'); | 
| 142: | $sig_tarea = new XoopsFormTextArea('', 'user_sig', $sig_value); | 
| 143: | $sig_tray->addElement($sig_tarea); | 
| 144: | $sig_cbox = new XoopsFormCheckBox('', 'attachsig', $sig_cbox_value); | 
| 145: | $sig_cbox->addOption(1, _AM_SYSTEM_USERS_SHOWSIG); | 
| 146: | $sig_tray->addElement($sig_cbox); | 
| 147: | $form->addElement($sig_tray); | 
| 148: | $umode_select = new XoopsFormSelect(_AM_SYSTEM_USERS_CDISPLAYMODE, 'umode', $umode_value); | 
| 149: | $umode_select->addOptionArray(array('nest' => _NESTED, 'flat' => _FLAT, 'thread' => _THREADED)); | 
| 150: | $form->addElement($umode_select); | 
| 151: | $uorder_select = new XoopsFormSelect(_AM_SYSTEM_USERS_CSORTORDER, 'uorder', $uorder_value); | 
| 152: | $uorder_select->addOptionArray(array('0' => _OLDESTFIRST, '1' => _NEWESTFIRST)); | 
| 153: | $form->addElement($uorder_select); | 
| 154: |  | 
| 155: | $notify_method_select = new XoopsFormSelect(_NOT_NOTIFYMETHOD, 'notify_method', $notify_method_value); | 
| 156: | $notify_method_select->addOptionArray(array( | 
| 157: | XOOPS_NOTIFICATION_METHOD_DISABLE => _NOT_METHOD_DISABLE, | 
| 158: | XOOPS_NOTIFICATION_METHOD_PM      => _NOT_METHOD_PM, | 
| 159: | XOOPS_NOTIFICATION_METHOD_EMAIL   => _NOT_METHOD_EMAIL)); | 
| 160: | $form->addElement($notify_method_select); | 
| 161: | $notify_mode_select = new XoopsFormSelect(_NOT_NOTIFYMODE, 'notify_mode', $notify_mode_value); | 
| 162: | $notify_mode_select->addOptionArray(array( | 
| 163: | XOOPS_NOTIFICATION_MODE_SENDALWAYS         => _NOT_MODE_SENDALWAYS, | 
| 164: | XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE => _NOT_MODE_SENDONCE, | 
| 165: | XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT   => _NOT_MODE_SENDONCEPERLOGIN)); | 
| 166: | $form->addElement($notify_mode_select); | 
| 167: | $form->addElement(new XoopsFormTextArea(_AM_SYSTEM_USERS_EXTRAINFO, 'bio', $bio_value)); | 
| 168: | $rank_select = new XoopsFormSelect(_AM_SYSTEM_USERS_RANK, 'rank', $rank_value); | 
| 169: | $ranklist    = XoopsLists::getUserRankList(); | 
| 170: | if (count($ranklist) > 0) { | 
| 171: | $rank_select->addOption(0, '--------------'); | 
| 172: | $rank_select->addOptionArray($ranklist); | 
| 173: | } else { | 
| 174: | $rank_select->addOption(0, _AM_SYSTEM_USERS_NSRID); | 
| 175: | } | 
| 176: | $form->addElement($rank_select); | 
| 177: |  | 
| 178: | if (!$form_isedit) { | 
| 179: | $form->addElement(new XoopsFormPassword(_AM_SYSTEM_USERS_PASSWORD, 'password', 10, 32), true); | 
| 180: | $form->addElement(new XoopsFormPassword(_AM_SYSTEM_USERS_RETYPEPD, 'pass2', 10, 32), true); | 
| 181: | } else { | 
| 182: | $form->addElement(new XoopsFormPassword(_AM_SYSTEM_USERS_PASSWORD, 'password', 10, 32)); | 
| 183: | $form->addElement(new XoopsFormPassword(_AM_SYSTEM_USERS_RETYPEPD, 'pass2', 10, 32)); | 
| 184: | } | 
| 185: | $form->addElement(new XoopsFormRadioYN(_AM_SYSTEM_USERS_ACCEPT_EMAIL, 'user_mailok', $mailok_value)); | 
| 186: |  | 
| 187: |  | 
| 188: |  | 
| 189: | $gperm_handler = xoops_getHandler('groupperm'); | 
| 190: |  | 
| 191: | if ($gperm_handler->checkRight('system_admin', XOOPS_SYSTEM_GROUP, $xoopsUser->getGroups(), 1)) { | 
| 192: |  | 
| 193: | $group_select[] = new XoopsFormSelectGroup(_AM_SYSTEM_USERS_GROUPS, 'groups', false, $groups, 5, true); | 
| 194: | } else { | 
| 195: |  | 
| 196: | foreach ($groups as $key => $group) { | 
| 197: | $group_select[] = new XoopsFormHidden('groups[' . $key . ']', $group); | 
| 198: | } | 
| 199: | } | 
| 200: | foreach ($group_select as $group) { | 
| 201: | $form->addElement($group); | 
| 202: | unset($group); | 
| 203: | } | 
| 204: |  | 
| 205: | $form->addElement(new XoopsFormHidden('fct', 'users')); | 
| 206: | $form->addElement(new XoopsFormHidden('op', 'users_save')); | 
| 207: | $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit')); | 
| 208: |  | 
| 209: | if (!empty($uid_value)) { | 
| 210: | $form->addElement(new XoopsFormHidden('uid', $uid_value)); | 
| 211: | } | 
| 212: | $form->display(); | 
| 213: | } | 
| 214: |  | 
| 215: |  | 
| 216: |  | 
| 217: |  | 
| 218: |  | 
| 219: | function synchronize($uid, $type) | 
| 220: | { | 
| 221: | global $xoopsDB; | 
| 222: |  | 
| 223: | include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; | 
| 224: | include_once XOOPS_ROOT_PATH . '/kernel/module.php'; | 
| 225: |  | 
| 226: | $tables = array(); | 
| 227: |  | 
| 228: | $tables[] = array('table_name' => 'xoopscomments', 'uid_column' => 'com_uid', 'criteria' => new Criteria('com_status', XOOPS_COMMENT_ACTIVE)); | 
| 229: |  | 
| 230: | if (XoopsModule::getByDirname('fmcontent')) { | 
| 231: | $tables[] = array('table_name' => 'fmcontent_content', 'uid_column' => 'content_uid'); | 
| 232: | } | 
| 233: |  | 
| 234: | if (XoopsModule::getByDirname('newbb')) { | 
| 235: |  | 
| 236: | $tableTest = new \Xmf\Database\Tables(); | 
| 237: | if($tableTest->useTable('newbb_posts')) { | 
| 238: | $tables[] = array('table_name' => 'newbb_posts', 'uid_column' => 'uid'); | 
| 239: | } else { | 
| 240: | $tables[] = array('table_name' => 'bb_posts', 'uid_column' => 'uid'); | 
| 241: | } | 
| 242: | } | 
| 243: |  | 
| 244: | switch ($type) { | 
| 245: | case 'user': | 
| 246: | $total_posts = 0; | 
| 247: | foreach ($tables as $table) { | 
| 248: | $criteria = new CriteriaCompo(); | 
| 249: | $criteria->add(new Criteria($table['uid_column'], $uid)); | 
| 250: | if (!empty($table['criteria'])) { | 
| 251: | $criteria->add($table['criteria']); | 
| 252: | } | 
| 253: | $sql = 'SELECT COUNT(*) AS total FROM ' . $xoopsDB->prefix($table['table_name']) . ' ' . $criteria->renderWhere(); | 
| 254: | $result = $xoopsDB->query($sql); | 
| 255: | if ($xoopsDB->isResultSet($result)) { | 
| 256: | if ($row = $xoopsDB->fetchArray($result)) { | 
| 257: | $total_posts += $row['total']; | 
| 258: | } | 
| 259: | } | 
| 260: | } | 
| 261: | $sql = 'UPDATE ' . $xoopsDB->prefix('users') . " SET posts = '" . $total_posts . "' WHERE uid = '" . $uid . "'"; | 
| 262: | $result = $xoopsDB->queryF($sql); | 
| 263: | if (!$xoopsDB->isResultSet($result)) { | 
| 264: | redirect_header('admin.php?fct=users', 1, _AM_SYSTEM_USERS_CNUUSER); | 
| 265: | } | 
| 266: | break; | 
| 267: |  | 
| 268: | case 'all users': | 
| 269: | $sql = 'SELECT uid FROM ' . $xoopsDB->prefix('users') . ''; | 
| 270: | $result = $xoopsDB->query($sql); | 
| 271: | if (!$xoopsDB->isResultSet($result)) { | 
| 272: | redirect_header('admin.php?fct=users', 1, sprintf(_AM_SYSTEM_USERS_CNGUSERID, $uid)); | 
| 273: | } | 
| 274: |  | 
| 275: | while (false !== ($data = $xoopsDB->fetchArray($result))) { | 
| 276: | synchronize($data['uid'], 'user'); | 
| 277: | } | 
| 278: | break; | 
| 279: | } | 
| 280: |  | 
| 281: |  | 
| 282: | } | 
| 283: |  |