1: <?php
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31: use Xoops\Core\Kernel\Criteria;
32: use Xoops\Core\Kernel\CriteriaCompo;
33: use Xoops\Core\Request;
34: use Xoops\Core\FixedGroups;
35:
36: $xoops = Xoops::getInstance();
37:
38:
39: if (!$xoops->isUser() || !$xoops->isModule() || !$xoops->userIsAdmin) {
40: exit(XoopsLocale::E_NO_ACCESS_PERMISSION);
41: }
42:
43: XoopsLoad::loadFile($xoops->path('modules/system/admin/users/users.php'));
44:
45: $op = $system->cleanVars($_REQUEST, 'op', 'default', 'string');
46:
47: $member_handler = $xoops->getHandlerMember();
48:
49:
50: $xoops->header('admin:system/system_users.tpl');
51:
52: $myts = \Xoops\Core\Text\Sanitizer::getInstance();
53:
54: $xoops->theme()->addStylesheet('modules/system/css/admin.css');
55:
56: $xoops->theme()->addScript('modules/system/js/admin.js');
57:
58: $system_breadcrumb->addLink(SystemLocale::USERS_MANAGEMENT, system_adminVersion('users', 'adminpath'));
59:
60: $uid = $system->cleanVars($_REQUEST, 'uid', 0);
61: switch ($op) {
62:
63:
64: case 'users_edit':
65:
66: $admin_page = new \Xoops\Module\Admin();
67: $admin_page->addBreadcrumbLink(SystemLocale::CONTROL_PANEL, \XoopsBaseConfig::get('url') . '/admin.php', true);
68: $admin_page->addBreadcrumbLink(SystemLocale::USERS_MANAGEMENT, $system->adminVersion('users', 'adminpath'));
69: $admin_page->addBreadcrumbLink(SystemLocale::EDIT_USER);
70: $admin_page->renderBreadcrumb();
71: $uid = $system->cleanVars($_GET, 'uid', 0);
72: $member_handler = $xoops->getHandlerMember();
73: $user = $member_handler->getUser($uid);
74: $form = $xoops->getModuleForm($user, 'user');
75: $form->display();
76: break;
77:
78:
79: case 'users_add':
80:
81: $admin_page = new \Xoops\Module\Admin();
82: $admin_page->addBreadcrumbLink(SystemLocale::CONTROL_PANEL, \XoopsBaseConfig::get('url') . '/admin.php', true);
83: $admin_page->addBreadcrumbLink(SystemLocale::USERS_MANAGEMENT, $system->adminVersion('users', 'adminpath'));
84: $admin_page->addBreadcrumbLink(SystemLocale::ADD_USER);
85: $admin_page->renderBreadcrumb();
86: $member_handler = $xoops->getHandlerMember();
87: $user = $member_handler->createUser();
88: $form = $xoops->getModuleForm($user, 'user');
89: $form->display();
90: break;
91:
92:
93: case 'users_delete':
94:
95: $admin_page = new \Xoops\Module\Admin();
96: $admin_page->addBreadcrumbLink(SystemLocale::CONTROL_PANEL, \XoopsBaseConfig::get('url') . '/admin.php', true);
97: $admin_page->addBreadcrumbLink(SystemLocale::USERS_MANAGEMENT, $system->adminVersion('users', 'adminpath'));
98: $admin_page->addBreadcrumbLink(SystemLocale::DELETE_USER);
99: $admin_page->renderBreadcrumb();
100: $system_breadcrumb->render();
101: $user = $member_handler->getUser($uid);
102: if (isset($_REQUEST['ok']) && $_REQUEST['ok'] == 1) {
103: if (!$xoops->security()->check()) {
104: $xoops->redirect("admin.php?fct=users", 3, implode('<br />', $xoops->security()->getErrors()));
105: }
106:
107: $groups = $user->getGroups();
108: if (in_array(FixedGroups::ADMIN, $groups)) {
109: echo $xoops->alert('error', sprintf(SystemLocale::EF_CAN_NOT_DELETE_ADMIN_USER, $user->getVar("uname")));
110: } elseif (!$member_handler->deleteUser($user)) {
111: echo $xoops->alert('error', sprintf(SystemLocale::EF_COULD_NOT_DELETE_USER, $user->getVar("uname")));
112: } else {
113: $xoops->getHandlerOnline()->destroy($uid);
114: if ($xoops->isActiveModule('notifications')) {
115: Notifications::getInstance()->getHandlerNotification()->unsubscribeByUser($uid);
116: }
117: $xoops->redirect("admin.php?fct=users", 1, XoopsLocale::S_DATABASE_UPDATED);
118: }
119: } else {
120:
121: $system_breadcrumb->addHelp(system_adminVersion('users', 'help') . '#delete');
122: $system_breadcrumb->addLink(SystemLocale::DELETE_USER);
123: $system_breadcrumb->render();
124: echo $xoops->confirm(array(
125: 'ok' => 1, 'uid' => $uid, 'op' => 'users_delete'
126: ), "admin.php?fct=users", sprintf(SystemLocale::F_DELETE_USER, $user->getVar('uname')) . '<br />');
127: }
128: break;
129:
130:
131: case "action_group":
132: if ((@isset($_REQUEST['memberslist_id']) || @$_REQUEST['memberslist_id'] != '')) {
133: $system_breadcrumb->render();
134: $error = '';
135: foreach ($_REQUEST['memberslist_id'] as $del) {
136: $del = (int)($del);
137: $user = $member_handler->getUser($del);
138: $groups = $user->getGroups();
139: if (in_array(FixedGroups::ADMIN, $groups)) {
140: $error .= sprintf(SystemLocale::EF_CAN_NOT_DELETE_ADMIN_USER, $user->getVar("uname"));
141: $error .= '<br />';
142: } elseif (!$member_handler->deleteUser($user)) {
143: $error .= sprintf(SystemLocale::EF_COULD_NOT_DELETE_USER, $user->getVar("uname"));
144: $error .= '<br />';
145: } else {
146: $xoops->getHandlerOnline()->destroy($del);
147:
148: if ($xoops->isActiveModule('notifications')) {
149: Notifications::getInstance()->getHandlerNotification()->unsubscribeByUser($del);
150: }
151: }
152: }
153: if ($error != '') {
154: $xoops->redirect("admin.php?fct=users", 3, sprintf(XoopsLocale::F_ERROR, $error));
155: } else {
156: $xoops->redirect("admin.php?fct=users", 1, XoopsLocale::S_DATABASE_UPDATED);
157: }
158: }
159: break;
160:
161:
162: case "users_save":
163: if (isset($_REQUEST['uid'])) {
164:
165: if (!$xoops->security()->check()) {
166: $xoops->redirect("admin.php?fct=users", 3, implode('<br />', $xoops->security()->getErrors()));
167: }
168:
169: $user_avatar = $theme = null;
170: if (!isset($_REQUEST['attachsig'])) {
171: $attachsig = null;
172: }
173: if (!isset($_REQUEST['user_viewemail'])) {
174: $user_viewemail = null;
175: }
176:
177: $edituser = $member_handler->getUser($uid);
178: if ($edituser->getVar('uname', 'n') != $_REQUEST['username'] && $member_handler->getUserCount(new Criteria('uname', $_REQUEST['username'])) > 0) {
179: $xoops->header();
180: echo $xoops->alert('error', sprintf(XoopsLocale::EF_USER_NAME_ALREADY_EXISTS, $myts->htmlSpecialChars($_REQUEST['username'])));
181: $xoops->footer();
182: } elseif ($edituser->getVar('email', 'n') != $_REQUEST['email'] && $member_handler->getUserCount(new Criteria('email', $_REQUEST['email'])) > 0) {
183: $xoops->header();
184: echo $xoops->alert('error', sprintf(XoopsLocale::EF_EMAIL_ALREADY_EXISTS, $myts->htmlSpecialChars($_REQUEST['email'])));
185: $xoops->footer();
186: } else {
187: $edituser->setVar("name", $_REQUEST['name']);
188: $edituser->setVar("uname", $_REQUEST['username']);
189: $edituser->setVar("email", $_REQUEST['email']);
190: $url = isset($_REQUEST['url']) ? $xoops->formatURL($_REQUEST['url']) : '';
191: $edituser->setVar("url", $url);
192: $edituser->setVar("user_icq", $_REQUEST['user_icq']);
193: $edituser->setVar("user_from", $_REQUEST['user_from']);
194: $edituser->setVar("user_sig", $_REQUEST['user_sig']);
195: $user_viewemail = (isset($_REQUEST['user_viewemail']) && $_REQUEST['user_viewemail'] == 1) ? 1 : 0;
196: $edituser->setVar("user_viewemail", $user_viewemail);
197: $edituser->setVar("user_aim", $_REQUEST['user_aim']);
198: $edituser->setVar("user_yim", $_REQUEST['user_yim']);
199: $edituser->setVar("user_msnm", $_REQUEST['user_msnm']);
200: $attachsig = (isset($_REQUEST['attachsig']) && $_REQUEST['attachsig'] == 1) ? 1 : 0;
201: $edituser->setVar("attachsig", $attachsig);
202: $edituser->setVar("timezone", $_REQUEST['timezone']);
203:
204:
205:
206:
207:
208: $edituser->setVar("bio", $_REQUEST['bio']);
209: $edituser->setVar("rank", $_REQUEST['rank']);
210: $edituser->setVar("user_occ", $_REQUEST['user_occ']);
211: $edituser->setVar("user_intrest", $_REQUEST['user_intrest']);
212: $edituser->setVar('user_mailok', $_REQUEST['user_mailok']);
213: if ($_REQUEST['pass2'] != "") {
214: if ($_REQUEST['password'] != $_REQUEST['pass2']) {
215: $xoops->header();
216: echo "
217: <strong>" . SystemLocale::E_NEW_PASSWORDS_NOT_MATCH_TRY_AGAIN . "</strong>";
218: $xoops->footer();
219: exit();
220: }
221: $edituser->setVar("pass", password_hash($_REQUEST['password'], PASSWORD_DEFAULT));
222: }
223: if (!$member_handler->insertUser($edituser)) {
224: $xoops->header();
225: echo $edituser->getHtmlErrors();
226: $xoops->footer();
227: } else {
228: if ($_REQUEST['groups'] != array()) {
229: $oldgroups = $edituser->getGroups();
230:
231: if ($edituser->getVar('uid') == $xoops->user->getVar('uid') && (in_array(FixedGroups::ADMIN, $oldgroups)) && !(in_array(FixedGroups::ADMIN, $_REQUEST['groups']))) {
232:
233: array_push($_REQUEST['groups'], FixedGroups::ADMIN);
234: }
235: $member_handler = $xoops->getHandlerMember();
236: foreach ($oldgroups as $groupid) {
237: $member_handler->removeUsersFromGroup($groupid, array($edituser->getVar('uid')));
238: }
239: foreach ($_REQUEST['groups'] as $groupid) {
240: $member_handler->addUserToGroup($groupid, $edituser->getVar('uid'));
241: }
242: }
243: $xoops->redirect("admin.php?fct=users", 1, XoopsLocale::S_DATABASE_UPDATED);
244: }
245: }
246: exit();
247: } else {
248:
249: if (!$xoops->security()->check()) {
250: $xoops->redirect("admin.php?fct=users", 3, implode('<br />', $xoops->security()->getErrors()));
251: }
252: if (!$_REQUEST['username'] || !$_REQUEST['email'] || !$_REQUEST['password']) {
253: $adduser_errormsg = XoopsLocale::E_YOU_MUST_COMPLETE_ALL_REQUIRED_FIELDS;
254: } else {
255: $member_handler = $xoops->getHandlerMember();
256:
257: if ($member_handler->getUserCount(new Criteria('uname', $_REQUEST['username'])) > 0) {
258: $adduser_errormsg = 'User name ' . $myts->htmlSpecialChars($_REQUEST['username']) . ' already exists';
259: } else {
260: $newuser = $member_handler->createUser();
261: if (isset($user_viewemail)) {
262: $newuser->setVar("user_viewemail", $_REQUEST['user_viewemail']);
263: }
264: if (isset($attachsig)) {
265: $newuser->setVar("attachsig", $_REQUEST['attachsig']);
266: }
267: $newuser->setVar("name", $_REQUEST['name']);
268: $newuser->setVar("uname", $_REQUEST['username']);
269: $newuser->setVar("email", $_REQUEST['email']);
270: $newuser->setVar("url", $xoops->formatURL($_REQUEST['url']));
271: $newuser->setVar("user_avatar", 'blank.gif');
272: $newuser->setVar('user_regdate', time());
273: $newuser->setVar("user_icq", $_REQUEST['user_icq']);
274: $newuser->setVar("user_from", $_REQUEST['user_from']);
275: $newuser->setVar("user_sig", $_REQUEST['user_sig']);
276: $newuser->setVar("user_aim", $_REQUEST['user_aim']);
277: $newuser->setVar("user_yim", $_REQUEST['user_yim']);
278: $newuser->setVar("user_msnm", $_REQUEST['user_msnm']);
279: if ($_REQUEST['pass2'] != "") {
280: if ($_REQUEST['password'] != $_REQUEST['pass2']) {
281: $xoops->header();
282: echo "<strong>" . SystemLocale::E_NEW_PASSWORDS_NOT_MATCH_TRY_AGAIN . "</strong>";
283: $xoops->footer();
284: exit();
285: }
286: $newuser->setVar("pass", password_hash($_REQUEST['password'], PASSWORD_DEFAULT));
287: }
288: $newuser->setVar("timezone", $_REQUEST['timezone']);
289:
290:
291:
292:
293:
294: $newuser->setVar("bio", $_REQUEST['bio']);
295: $newuser->setVar("rank", $_REQUEST['rank']);
296: $newuser->setVar("level", 1);
297: $newuser->setVar("user_occ", $_REQUEST['user_occ']);
298: $newuser->setVar("user_intrest", $_REQUEST['user_intrest']);
299: $newuser->setVar('user_mailok', $_REQUEST['user_mailok']);
300: if (!$member_handler->insertUser($newuser)) {
301: $adduser_errormsg = XoopsLocale::E_USER_NOT_REGISTERED;
302: } else {
303: $groups_failed = array();
304: foreach ($_REQUEST['groups'] as $group) {
305: $group = (int)($group);
306: if (!$member_handler->addUserToGroup($group, $newuser->getVar('uid'))) {
307: $groups_failed[] = $group;
308: }
309: }
310: if (!empty($groups_failed)) {
311: $group_names = $member_handler->getGroupList(new Criteria('groupid', "(" . implode(", ", $groups_failed) . ")", 'IN'));
312: $adduser_errormsg = sprintf(SystemLocale::EF_COULD_NOT_ADD_USER_TO_GROUPS, implode(", ", $group_names));
313: } else {
314: XoopsUserUtility::sendWelcome($newuser);
315: $xoops->redirect("admin.php?fct=users", 1, XoopsLocale::S_DATABASE_UPDATED);
316: exit();
317: }
318: }
319: }
320: }
321: echo $xoops->alert('error', $adduser_errormsg);
322: }
323: break;
324:
325:
326: case 'users_active':
327: $obj = $member_handler->getUser($uid);
328: $obj->setVar("level", 1);
329: if ($member_handler->insertUser($obj, true)) {
330: $xoops->redirect("admin.php?fct=users", 1, XoopsLocale::S_DATABASE_UPDATED);
331: }
332: echo $obj->getHtmlErrors();
333: break;
334:
335:
336: case 'users_synchronize':
337: if (isset($_REQUEST['status']) && $_REQUEST['status'] == 1) {
338: synchronize($$uid, 'user');
339: } else {
340: if (isset($_REQUEST['status']) && $_REQUEST['status'] == 2) {
341: synchronize('', 'all users');
342: }
343: }
344: $xoops->redirect("admin.php?fct=users", 1, XoopsLocale::S_DATABASE_UPDATED);
345: break;
346:
347: default:
348:
349:
350: $xoops->theme()->addBaseScriptAssets('@jqueryui', 'modules/system/js/admin.js');
351:
352:
353:
354:
355:
356: if (isset($_REQUEST['complet_search'])) {
357:
358: $admin_page = new \Xoops\Module\Admin();
359: $admin_page->addBreadcrumbLink(SystemLocale::CONTROL_PANEL, \XoopsBaseConfig::get('url') . '/admin.php', true);
360: $admin_page->addBreadcrumbLink(SystemLocale::USERS_MANAGEMENT, $system->adminVersion('users', 'adminpath'));
361: $admin_page->addBreadcrumbLink(XoopsLocale::ADVANCED_SEARCH);
362: $admin_page->renderBreadcrumb();
363:
364: $acttotal = $member_handler->getUserCount(new Criteria('level', 0, '>'));
365: $inacttotal = $member_handler->getUserCount(new Criteria('level', 0));
366: $group_select = new Xoops\Form\Select(XoopsLocale::GROUPS, "selgroups");
367: $group_handler = $xoops->getHandlerGroup();
368: $group_arr = $group_handler->getObjects();
369: $group_select->addOption("", "--------------");
370:
371: foreach ($group_arr as $group) {
372: if ($group->getVar("groupid") != 3) {
373: $group_select->addOption("" . $group->getVar("groupid") . "", "" . $group->getVar("name") . "");
374: }
375: }
376: unset($group);
377: $uname_text = new Xoops\Form\Text("", "user_uname", 30, 60);
378: $uname_match = new Xoops\Form\SelectMatchOption("", "user_uname_match");
379: $uname_tray = new Xoops\Form\ElementTray(XoopsLocale::USER_NAME, " ");
380: $uname_tray->addElement($uname_match);
381: $uname_tray->addElement($uname_text);
382: $name_text = new Xoops\Form\Text("", "user_name", 30, 60);
383: $name_match = new Xoops\Form\SelectMatchOption("", "user_name_match");
384: $name_tray = new Xoops\Form\ElementTray(XoopsLocale::REAL_NAME, " ");
385: $name_tray->addElement($name_match);
386: $name_tray->addElement($name_text);
387: $email_text = new Xoops\Form\Text("", "user_email", 30, 60);
388: $email_match = new Xoops\Form\SelectMatchOption("", "user_email_match");
389: $email_tray = new Xoops\Form\ElementTray(XoopsLocale::EMAIL, " ");
390: $email_tray->addElement($email_match);
391: $email_tray->addElement($email_text);
392: $url_text = new Xoops\Form\Text(XoopsLocale::URL_CONTAINS, "user_url", 30, 100);
393: $icq_text = new Xoops\Form\Text("", "user_icq", 30, 100);
394: $icq_match = new Xoops\Form\SelectMatchOption("", "user_icq_match");
395: $icq_tray = new Xoops\Form\ElementTray(XoopsLocale::ICQ, " ");
396: $icq_tray->addElement($icq_match);
397: $icq_tray->addElement($icq_text);
398: $aim_text = new Xoops\Form\Text("", "user_aim", 30, 100);
399: $aim_match = new Xoops\Form\SelectMatchOption("", "user_aim_match");
400: $aim_tray = new Xoops\Form\ElementTray(XoopsLocale::AIM, " ");
401: $aim_tray->addElement($aim_match);
402: $aim_tray->addElement($aim_text);
403: $yim_text = new Xoops\Form\Text("", "user_yim", 30, 100);
404: $yim_match = new Xoops\Form\SelectMatchOption("", "user_yim_match");
405: $yim_tray = new Xoops\Form\ElementTray(XoopsLocale::YIM, " ");
406: $yim_tray->addElement($yim_match);
407: $yim_tray->addElement($yim_text);
408: $msnm_text = new Xoops\Form\Text("", "user_msnm", 30, 100);
409: $msnm_match = new Xoops\Form\SelectMatchOption("", "user_msnm_match");
410: $msnm_tray = new Xoops\Form\ElementTray(XoopsLocale::MSNM, " ");
411: $msnm_tray->addElement($msnm_match);
412: $msnm_tray->addElement($msnm_text);
413: $location_text = new Xoops\Form\Text(XoopsLocale::LOCATION_CONTAINS, "user_from", 30, 100);
414: $occupation_text = new Xoops\Form\Text(XoopsLocale::OCCUPATION_CONTAINS, "user_occ", 30, 100);
415: $interest_text = new Xoops\Form\Text(XoopsLocale::INTEREST_CONTAINS, "user_intrest", 30, 100);
416:
417: $lastlog_more = new Xoops\Form\Text(SystemLocale::LAST_LOGIN_GREATER_THAN_X, "user_lastlog_more", 10, 5);
418: $lastlog_less = new Xoops\Form\Text(SystemLocale::LAST_LOGIN_LESS_THAN_X, "user_lastlog_less", 10, 5);
419: $reg_more = new Xoops\Form\Text(SystemLocale::REGISTRATION_DATE_GREATER_THAN_X, "user_reg_more", 10, 5);
420: $reg_less = new Xoops\Form\Text(SystemLocale::REGISTRATION_DATE_LESS_THAN_X, "user_reg_less", 10, 5);
421: $posts_more = new Xoops\Form\Text(SystemLocale::POSTS_NUMBER_GREATER_THAN_X, "user_posts_more", 10, 5);
422: $posts_less = new Xoops\Form\Text(SystemLocale::POSTS_NUMBER_LESS_THAN_X, "user_posts_less", 10, 5);
423: $mailok_radio = new Xoops\Form\Radio(XoopsLocale::TYPE_OF_USERS_TO_SHOW, "user_mailok", "both");
424: $mailok_radio->addOptionArray(array(
425: "mailok" => XoopsLocale::ONLY_USERS_THAT_ACCEPT_EMAIL, "mailng" => XoopsLocale::ONLY_USERS_THAT_DO_NOT_ACCEPT_EMAIL,
426: "both" => XoopsLocale::ALL_USERS
427: ));
428: $type_radio = new Xoops\Form\Radio(XoopsLocale::TYPE_OF_USERS_TO_SHOW, "user_type", "both");
429: $type_radio->addOptionArray(array(
430: "actv" => SystemLocale::ONLY_ACTIVE_USERS, "inactv" => SystemLocale::ONLY_INACTIVE_USERS,
431: "both" => XoopsLocale::ALL_USERS
432: ));
433: $sort_select = new Xoops\Form\Select(XoopsLocale::SORT_BY, "user_sort", 'uname');
434: $sort_select->addOptionArray(array(
435: "uname" => XoopsLocale::USER_NAME, "email" => XoopsLocale::EMAIL,
436: "last_login" => XoopsLocale::LAST_LOGIN, "user_regdate" => XoopsLocale::REGISTRATION_DATE,
437: "posts" => XoopsLocale::COMMENTS_POSTS
438: ));
439: $order_select = new Xoops\Form\Select(XoopsLocale::ORDER, "user_order", 'ASC');
440: $order_select->addOptionArray(array("ASC" => XoopsLocale::ASCENDING, "DESC" => XoopsLocale::DESCENDING));
441: $limit_text = new Xoops\Form\Text(XoopsLocale::NUMBER_OF_RESULTS_PER_PAGE, "user_limit", 6, 2, 20);
442: $submit_button = new Xoops\Form\Button("", "user_submit", XoopsLocale::A_SUBMIT, "submit");
443:
444: $form = new Xoops\Form\ThemeForm(XoopsLocale::FIND_USERS, "user_findform", "admin.php?fct=users", 'post', true);
445: $form->addElement($uname_tray);
446: $form->addElement($name_tray);
447: $form->addElement($email_tray);
448: $form->addElement($group_select);
449: $form->addElement($icq_tray);
450: $form->addElement($aim_tray);
451: $form->addElement($yim_tray);
452: $form->addElement($msnm_tray);
453: $form->addElement($url_text);
454: $form->addElement($location_text);
455: $form->addElement($occupation_text);
456: $form->addElement($interest_text);
457: $form->addElement($lastlog_more);
458: $form->addElement($lastlog_less);
459: $form->addElement($reg_more);
460: $form->addElement($reg_less);
461: $form->addElement($posts_more);
462: $form->addElement($posts_less);
463: $form->addElement($mailok_radio);
464: $form->addElement($type_radio);
465: $form->addElement($sort_select);
466: $form->addElement($order_select);
467: $form->addElement($limit_text);
468:
469:
470: if (!empty($_GET['group']) && (int)($_GET['group']) > 0) {
471: $group_hidden = new Xoops\Form\Hidden("group", (int)($_GET['group']));
472: $form->addElement($group_hidden);
473: }
474: $form->addElement($submit_button);
475: $form->display();
476: } else {
477:
478:
479: $admin_page = new \Xoops\Module\Admin();
480: $admin_page->addBreadcrumbLink(SystemLocale::CONTROL_PANEL, \XoopsBaseConfig::get('url') . '/admin.php', true);
481: $admin_page->addBreadcrumbLink(SystemLocale::USERS_MANAGEMENT, $system->adminVersion('users', 'adminpath'));
482: $admin_page->addBreadcrumbLink(XoopsLocale::LIST_);
483: $admin_page->renderBreadcrumb();
484: $admin_page->addTips(SystemLocale::USERS_TIPS);
485: $admin_page->renderTips();
486: $admin_page->addItemButton(XoopsLocale::A_SYNCHRONIZE, 'admin.php?fct=users&op=users_synchronize&status=2', 'arrow-rotate-anticlockwise');
487: $admin_page->addItemButton(SystemLocale::ADD_USER, 'admin.php?fct=users&op=users_add', 'add');
488: $admin_page->renderButton();
489:
490: $requete_search = '<br /><br /><strong>' . SystemLocale::C_SEE_SEARCH_REQUEST . '</strong><br /><br />';
491: $requete_pagenav = '';
492:
493: $criteria = new CriteriaCompo();
494:
495: $value = Request::getString('user_uname', '');
496: if (!empty($value)) {
497: $match = Request::getInt('user_uname_match', XOOPS_MATCH_START);
498: addCriteria($criteria, 'uname', $value, $match);
499: $requete_pagenav .= '&user_uname=' . $myts->htmlSpecialChars($value) . '&user_uname_match=' . $match;
500: $requete_search .= 'uname : ' . $value . ' and user_uname_match=' . $match . '<br />';
501: }
502:
503: $value = Request::getString('user_name', '');
504: if (!empty($value)) {
505: $match = Request::getInt('user_name_match', XOOPS_MATCH_START);
506: addCriteria($criteria, 'name', $value, $match);
507: $requete_pagenav .= '&user_name=' . $myts->htmlSpecialChars($value) . '&user_name_match=' . $match;
508: $requete_search .= 'name : ' . $value . ' and user_name_match=' . $match . '<br />';
509: }
510:
511: $value = Request::getString('user_email', '');
512: if (!empty($value)) {
513: $match = Request::getInt('user_email_match', XOOPS_MATCH_START);
514: addCriteria($criteria, 'email', $value, $match);
515: $requete_pagenav .= '&user_email=' . $myts->htmlSpecialChars($value) . '&user_email_match=' . $match;
516: $requete_search .= 'email : ' . $value . ' and user_email_match=' . $match . '<br />';
517: }
518:
519: $value = Request::getString('user_url', '');
520: if (!empty($value)) {
521:
522: $criteria->add(new Criteria('url', '%' . $value . '%', 'LIKE'));
523: $requete_search .= 'url : ' . $value . '<br />';
524: }
525:
526: $value = Request::getInt('user_icq', 0);
527: if (!empty($value)) {
528: $match = Request::getInt('user_icq_match', XOOPS_MATCH_START);
529: addCriteria($criteria, 'user_icq', (string) $value, $match);
530: $requete_pagenav .= '&user_icq=' . $value . '&user_icq_match=' . $match;
531: $requete_search .= 'icq : ' . $value . ' and user_icq_match=' . $match . '<br />';
532: }
533:
534: $value = Request::getString('user_aim', '');
535: if (!empty($value)) {
536: $match = Request::getInt('user_aim_match', XOOPS_MATCH_START);
537: addCriteria($criteria, 'user_aim', $value, $match);
538: $requete_pagenav .= '&user_aim=' . $myts->htmlSpecialChars($value) . '&user_aim_match=' . $match;
539: $requete_search .= 'aim : ' . $value . ' and user_aim_match=' . $match . '<br />';
540: }
541:
542: $value = Request::getString('user_yim', '');
543: if (!empty($value)) {
544: $match = Request::getInt('user_yim_match', XOOPS_MATCH_START);
545: addCriteria($criteria, 'user_yim', $value, $match);
546: $requete_pagenav .= '&user_yim=' . $myts->htmlSpecialChars($value) . '&user_yim_match=' . $match;
547: $requete_search .= 'yim : ' . $value . ' and user_yim_match=' . $match . '<br />';
548: }
549:
550: $value = Request::getString('user_msnm', '');
551: if (!empty($value)) {
552: $match = Request::getInt('user_msnm_match', XOOPS_MATCH_START);
553: addCriteria($criteria, 'user_msnm', $value, $match);
554: $requete_pagenav .= '&user_msnm=' . $myts->htmlSpecialChars($value) . '&user_msnm_match=' . $match;
555: $requete_search .= 'msnm : ' . $value . ' and user_msnm_match=' . $match . '<br />';
556: }
557:
558: $value = Request::getString('user_from', '');
559: if (!empty($value)) {
560: $criteria->add(new Criteria('user_from', '%' . $value . '%', 'LIKE'));
561: $requete_pagenav .= '&user_from=' . $myts->htmlSpecialChars($value);
562: $requete_search .= 'from : ' . $value . '<br />';
563: }
564:
565: $value = Request::getString('user_intrest', '');
566: if (!empty($value)) {
567: $criteria->add(new Criteria('user_intrest', '%' . $value . '%', 'LIKE'));
568: $requete_pagenav .= '&user_intrest=' . $myts->htmlSpecialChars($value);
569: $requete_search .= 'interet : ' . $value . '<br />';
570: }
571:
572: $value = Request::getString('user_occ', '');
573: if (!empty($value)) {
574: $criteria->add(new Criteria('user_occ', '%' . $value . '%', 'LIKE'));
575: $requete_pagenav .= '&user_occ=' . $myts->htmlSpecialChars($value);
576: $requete_search .= 'location : ' . $value . '<br />';
577: }
578:
579: $value = Request::getInt('user_lastlog_more', 0);
580: if (!empty($value)) {
581: $time = time() - (60 * 60 * 24 * $value);
582: if ($time > 0) {
583: $criteria->add(new Criteria('last_login', $time, '<'));
584: $requete_pagenav .= '&user_lastlog_more=' . $value;
585: $requete_search .= 'derniere connexion apres : ' . $value . '<br />';
586: }
587: }
588:
589: $value = Request::getInt('user_lastlog_less', 0);
590: if (!empty($value)) {
591: $time = time() - (60 * 60 * 24 * $value);
592: if ($time > 0) {
593: $criteria->add(new Criteria('last_login', $time, '>'));
594: $requete_pagenav .= '&user_lastlog_less=' . $value;
595: $requete_search .= 'derniere connexion avant : ' . $value . '<br />';
596: }
597: }
598:
599: $value = Request::getInt('user_reg_more', 0);
600: if (!empty($value)) {
601: $time = time() - (60 * 60 * 24 * $value);
602: if ($time > 0) {
603: $criteria->add(new Criteria('user_regdate', $time, '<'));
604: $requete_pagenav .= '&user_reg_more=' . $value;
605: $requete_search .= 'enregistre apres : ' . $value . '<br />';
606: }
607: }
608:
609: $value = Request::getInt('user_reg_less', 0);
610: if (!empty($value)) {
611: $time = time() - (60 * 60 * 24 * $value);
612: if ($time > 0) {
613: $criteria->add(new Criteria('user_regdate', $time, '>'));
614: $requete_pagenav .= '&user_reg_less=' . $value;
615: $requete_search .= 'enregistre avant : ' . $value . '<br />';
616: }
617: }
618:
619: $value = Request::getInt('user_posts_more', 0);
620: if (!empty($value)) {
621: $criteria->add(new Criteria('posts', $value, '>'));
622: $requete_pagenav .= '&user_posts_more=' . $value;
623: $requete_search .= 'posts plus de : ' . $value . '<br />';
624: }
625:
626: $value = Request::getInt('user_posts_less', 0);
627: if (!empty($value)) {
628: $criteria->add(new Criteria('posts', $value, '<'));
629: $requete_pagenav .= '&user_posts_less=' . $value;
630: $requete_search .= 'post moins de : ' . $value . '<br />';
631: }
632:
633: $value = Request::getWord('user_mailok', '');
634: if (!empty($value) && ($value !== 'both')) {
635: $ok = ($value === 'mailok') ? 1 : 0;
636: $criteria->add(new Criteria('user_mailok', $ok));
637: $requete_pagenav .= '&user_mailok=' . $value;
638: $requete_search .= 'accept email : ' . $value . '<br />';
639: }
640:
641: $user_type = Request::getWord('user_type', '');
642: if (!empty($user_type) && ($user_type !== 'both')) {
643: if ($user_type === 'inactv') {
644: $criteria->add(new Criteria('level', 0, '='));
645: } elseif ($user_type === "actv") {
646: $criteria->add(new Criteria('level', 0, '>'));
647: }
648: $requete_search .= 'actif ou inactif : ' . $user_type . '<br />';
649: $requete_pagenav .= '&user_type=' . $user_type;
650: }
651:
652:
653: $validsort = array("uname", "email", "last_login", "user_regdate", "posts");
654: $sort = Request::getWord('user_sort', 'user_regdate');
655: $sort = (!in_array($sort, $validsort)) ? "user_regdate" : $sort;
656: $requete_pagenav .= '&user_sort=' . $sort;
657: $requete_search .= 'order by : ' . $sort . '<br />';
658: $criteria->setSort($sort);
659:
660: $order = Request::getWord('user_order', 'DESC');
661: $requete_pagenav .= '&user_order=' . $order;
662: $requete_search .= 'tris : ' . $order . '<br />';
663: $criteria->setOrder($order);
664:
665: $user_limit = $xoops->getModuleConfig('users_pager', 'system');
666: if (isset($_REQUEST['user_limit'])) {
667: $user_limit = $_REQUEST['user_limit'];
668: $requete_pagenav .= '&user_limit=' . $myts->htmlSpecialChars($_REQUEST['user_limit']);
669: $requete_search .= 'limit : ' . $user_limit . '<br />';
670: } else {
671: $requete_pagenav .= '&user_limit=' . $xoops->getModuleConfig('users_pager', 'system');
672: $requete_search .= 'limit : ' . $user_limit . '<br />';
673: }
674:
675: $start = (!empty($_REQUEST['start'])) ? (int)($_REQUEST['start']) : 0;
676:
677: if (isset($_REQUEST['selgroups'])) {
678: if ($_REQUEST['selgroups'] != 0) {
679: if (count($_REQUEST['selgroups']) == 1) {
680: $groups = array(0 => $_REQUEST['selgroups']);
681: } else {
682: $groups = array_map("intval", $_REQUEST['selgroups']);
683: }
684: } else {
685: $groups = array();
686: }
687: $requete_pagenav .= '&selgroups=' . $myts->htmlSpecialChars($_REQUEST['selgroups']);
688: } else {
689: $groups = array();
690: }
691:
692: $member_handler = $xoops->getHandlerMember();
693: $users_count = $member_handler->getUserCountByGroupLink($groups, $criteria);
694: $users_arr = array();
695: if ($start < $users_count) {
696: echo sprintf(XoopsLocale::F_USERS_FOUND, $users_count) . "<br />";
697: $criteria->setSort($sort);
698: $criteria->setOrder($order);
699: $criteria->setLimit($user_limit);
700: $criteria->setStart($start);
701: $users_arr = $member_handler->getUsersByGroupLink($groups, $criteria, true);
702: $ucount = 0;
703: }
704:
705: $xoops->tpl()->assign('users_count', $users_count);
706: $xoops->tpl()->assign('users_display', true);
707: $xoops->tpl()->assign('php_selft', $_SERVER['PHP_SELF']);
708:
709:
710:
711:
712:
713:
714: $selgroups = (!isset($_REQUEST['selgroups'])) ? '' : $_REQUEST['selgroups'];
715:
716: $user_uname = (!isset($_REQUEST['user_uname'])) ? '' : $_REQUEST['user_uname'];
717:
718: $form = '<form action="admin.php?fct=users" method="post">
719: ' . SystemLocale::C_SEARCH_USER . '<input type="text" name="user_uname" value="' . $myts->htmlSpecialChars($user_uname) . '" size="15">
720: <select name="selgroups">
721: <option value="" selected="selected">' . XoopsLocale::ALL_GROUPS . '</option>';
722: $group_handler = $xoops->getHandlerGroup();
723: $group_arr = $group_handler->getObjects();
724:
725: foreach ($group_arr as $group) {
726: if ($group->getVar("groupid") != 3) {
727: $form .= '<option value="' . $group->getVar("groupid") . '" ' . ($selgroups == $group->getVar("groupid") ? ' selected="selected"' : '') . '>' . $group->getVar("name") . '</option>';
728: }
729: }
730: unset($group);
731: $form .= '</select>
732: <select name="user_type">
733: <option value="" ' . ($user_type == '' ? ' selected="selected"' : '') . '>' . XoopsLocale::ALL_USERS . '</option>
734: <option value="actv" ' . ($user_type === 'actv' ? ' selected="selected"' : '') . '>' . SystemLocale::ONLY_ACTIVE_USERS . '</option>
735: <option value="inactv" ' . ($user_type === 'inactv' ? ' selected="selected"' : '') . '>' . SystemLocale::ONLY_INACTIVE_USERS . '</option>
736: </select>
737: <select name="user_limit">
738: <option value="20" ' . ($user_limit == 20 ? ' selected="selected"' : '') . '>20</option>
739: <option value="50" ' . ($user_limit == 50 ? ' selected="selected"' : '') . '>50</option>
740: <option value="100" ' . ($user_limit == 100 ? ' selected="selected"' : '') . '>100</option>
741: </select>
742: <input type="hidden" name="user_uname_match" value="XOOPS_MATCH_START" />
743: <input class="btn" type="submit" value="' . XoopsLocale::A_SEARCH . '" name="speed_search">
744: <input class="btn success" type="submit" value="' . XoopsLocale::ADVANCED_SEARCH . '" name="complet_search"></form>
745: ';
746:
747:
748: $form_select_groups = '<select name="selgroups" id="selgroups" style="display:none;"><option value="">---------</option>';
749:
750: $group_handler = $xoops->getHandlerGroup();
751: $group_arr = $group_handler->getObjects();
752:
753: foreach ($group_arr as $group) {
754: if ($group->getVar("groupid") != 3) {
755: $form_select_groups .= '<option value="' . $group->getVar("groupid") . '" ' . ($selgroups == $group->getVar("groupid") ? ' selected="selected"' : '') . '>' . $group->getVar("name") . '</option>';
756: }
757: }
758: unset($group);
759: $form_select_groups .= '</select><input type="hidden" name="op" value="users_add_delete_group">';
760:
761: $xoops->tpl()->assign('form_sort', $form);
762: $xoops->tpl()->assign('form_select_groups', $form_select_groups);
763:
764: if ($users_count > 0) {
765:
766: $ListOfAdmins = $member_handler->getUsersByGroup(1);
767:
768: foreach ($users_arr as $user) {
769: $users['uid'] = $user->getVar("uid");
770:
771: if (in_array($users['uid'], $ListOfAdmins)) {
772: $users['group'] = system_AdminIcons('xoops/group_1.png');
773:
774: $users['checkbox_user'] = false;
775: } else {
776: $users['group'] = system_AdminIcons('xoops/group_2.png');
777:
778: $users['checkbox_user'] = true;
779: }
780: $users['name'] = $user->getVar("uid");
781: $users['name'] = $user->getVar("name");
782: $users['uname'] = $user->getVar("uname");
783: $users['email'] = $user->getVar("email");
784: $users['url'] = $user->getVar("url");
785: $avatar = $xoops->service('avatar')->getAvatarUrl($user)->getValue();
786: $users['user_avatar'] = (empty($avatar) ? system_AdminIcons('anonymous.png') : $avatar);
787: $users['reg_date'] = XoopsLocale::formatTimestamp($user->getVar("user_regdate"), "m");
788: if ($user->getVar("last_login") > 0) {
789: $users['last_login'] = XoopsLocale::formatTimestamp($user->getVar("last_login"), "m");
790: } else {
791: $users['last_login'] = SystemLocale::NEVER_CONNECTED;
792: }
793: $users['user_level'] = $user->getVar("level");
794: $users['user_icq'] = $user->getVar("user_icq");
795: $users['user_aim'] = $user->getVar("user_aim");
796: $users['user_yim'] = $user->getVar("user_yim");
797: $users['user_msnm'] = $user->getVar("user_msnm");
798:
799: $users['posts'] = $user->getVar("posts");
800:
801: $xoops->tpl()->appendByRef('users', $users);
802: $xoops->tpl()->appendByRef('users_popup', $users);
803: unset($users, $user);
804: }
805: } else {
806: $xoops->tpl()->assign('users_no_found', true);
807: }
808:
809: if ($users_count > $user_limit) {
810: $nav = new XoopsPageNav($users_count, $user_limit, $start, 'start', 'fct=users&op=default' . $requete_pagenav);
811: $xoops->tpl()->assign('nav', $nav->renderNav());
812: }
813: }
814: break;
815: }
816:
817: $xoops->footer();
818:
819: 820: 821: 822: 823: 824: 825: 826: 827: 828:
829: function addCriteria(CriteriaCompo $criteria, $column, $value, $match)
830: {
831: $relation = 'LIKE';
832: switch ($match) {
833: default:
834: case XOOPS_MATCH_START:
835: $value = $value . '%';
836: break;
837: case XOOPS_MATCH_END:
838: $value = '%' . $value;
839: break;
840: case XOOPS_MATCH_EQUAL:
841:
842: $relation = '=';
843: break;
844: case XOOPS_MATCH_CONTAIN:
845: $value = '%' . $value . '%';
846: break;
847: }
848: $criteria->add(new Criteria($column, $value, $relation));
849: }
850: