1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Xoops\Form;
13:
14: use Xoops\Core\Kernel\Criteria;
15: use Xoops\Core\Kernel\CriteriaCompo;
16:
17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28:
29: class SelectUser extends ElementTray
30: {
31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43:
44: public function __construct($caption, $name, $include_anon = false, $value = null, $size = 1, $multiple = false)
45: {
46: $xoops = \Xoops::getInstance();
47: $limit = 200;
48: $select_element = new Select('', $name, $value, $size, $multiple);
49: if ($include_anon) {
50: $select_element->addOption(0, $xoops->getConfig('anonymous'));
51: }
52: $member_handler = $xoops->getHandlerMember();
53: $user_count = $member_handler->getUserCount();
54: $value = is_array($value) ? $value : (empty($value) ? array() : array($value));
55: if ($user_count > $limit && count($value) > 0) {
56: $criteria = new CriteriaCompo(new Criteria('uid', '(' . implode(',', $value) . ')', 'IN'));
57: } else {
58: $criteria = new CriteriaCompo();
59: $criteria->setLimit($limit);
60: }
61: $criteria->setSort('uname');
62: $criteria->setOrder('ASC');
63: $users = $member_handler->getUserList($criteria);
64: $select_element->addOptionArray($users);
65: if ($user_count <= $limit) {
66: parent::__construct($caption, "", $name);
67: $this->addElement($select_element);
68: return;
69: }
70:
71: $js_addusers = "<script type='text/javascript'>
72: function addusers(opts){
73: var num = opts.substring(0, opts.indexOf(':'));
74: opts = opts.substring(opts.indexOf(':')+1, opts.length);
75: var sel = xoopsGetElementById('" . $name . "');
76: var arr = new Array(num);
77: for (var n=0; n < num; n++) {
78: var nm = opts.substring(0, opts.indexOf(':'));
79: opts = opts.substring(opts.indexOf(':')+1, opts.length);
80: var val = opts.substring(0, opts.indexOf(':'));
81: opts = opts.substring(opts.indexOf(':')+1, opts.length);
82: var txt = opts.substring(0, nm - val.length);
83: opts = opts.substring(nm - val.length, opts.length);
84: var added = false;
85: for (var k = 0; k < sel.options.length; k++) {
86: if(sel.options[k].value == val){
87: added = true;
88: break;
89: }
90: }
91: if (added == false) {
92: sel.options[k] = new Option(txt, val);
93: sel.options[k].selected = true;
94: }
95: }
96: return true;
97: }
98: </script>";
99: $token = $xoops->security()->createToken();
100: $action_tray = new ElementTray("", " | ");
101: $action_tray->addElement(
102: new Label(
103: '',
104: '<a href="#" onclick="var sel = xoopsGetElementById(\'' . $name
105: . '\');for (var i = sel.options.length-1; i >= 0; i--) {if (!sel.options[i].selected) '
106: .'{sel.options[i] = null;}}; return false;">' . \XoopsLocale::REMOVE_UNSELECTED_USERS . "</a>"
107: )
108: );
109: $action_tray->addElement(
110: new Label(
111: '',
112: '<a href="#" onclick="openWithSelfMain(\'' . \XoopsBaseConfig::get('url') . '/include/findusers.php?target='
113: . $name . '&multiple=' . $multiple . '&token=' . $token
114: . '\', \'userselect\', 800, 600, null); return false;" >'
115: . \XoopsLocale::SEARCH_USERS . "</a>" . $js_addusers
116: )
117: );
118: parent::__construct($caption, '<br /><br />', $name);
119: $this->addElement($select_element);
120: $this->addElement($action_tray);
121: }
122: }
123: