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