XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
function.message_userlist.php
1<?php
12
13if (!defined('XOOPS_ROOT_PATH')) {
14 exit();
15}
16function smarty_function_message_userlist($params, &$smarty)
17{
18 $name = isset($params['name']) ? trim($params['name']) : 'uname';
19 $username = isset($params['uname']) ? trim($params['uname']) : '';
20 $buid = isset($params['uid']) ? true : false;
21 $id = isset($params['id']) ? trim($params['id']) : 'user-select';
22 $placeholder = isset($params['placeholder']) ? trim($params['placeholder']) : 'Select a user';
23
24 $root = XCube_Root::getSingleton();
25 $db = $root->mController->getDB();
26
27 // Get users data
28 $users = [];
29 $sql = 'SELECT `uname`, `uid` FROM `' . $db->prefix('users') . '` ';
30 $sql.= 'WHERE `uid` <> ' . $root->mContext->mXoopsUser->get('uid') . ' ';
31 $sql.= 'ORDER BY `uname`';
32 $result = $db->query($sql);
33 while ([$uname, $uid] = $db->fetchRow($result)) {
34 $users[] = [
35 'uid' => $uid,
36 'uname' => htmlspecialchars($uname, ENT_QUOTES)
37 ];
38 }
39
40 // Create select element with modern styling
41 $html = '<select name="'.$name.'" id="'.$id.'" class="user-select">';
42 $html .= '<option value="">'.$placeholder.'</option>';
43
44 foreach ($users as $user) {
45 $value = $buid ? $user['uid'] : $user['uname'];
46 $selected = ((false == $buid && $user['uname'] == $username) ||
47 ($buid && $user['uid'] == $username)) ? ' selected="selected"' : '';
48 $html .= '<option value="'.$value.'"'.$selected.'>'.$user['uname'].'</option>';
49 }
50
51 $html .= '</select>';
52
53 // Add minimal CSS for styling
54 $html .= '<style>
55 .user-select {
56 width: 100%;
57 padding: 8px;
58 border: 1px solid #212121;
59 border-radius: 4px;
60 box-sizing: border-box;
61 }
62 </style>';
63
64 echo $html;
65}