XOOPS  2.6.0
SelectUser.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
12 namespace Xoops\Form;
13 
16 
30 class SelectUser extends ElementTray
31 {
45  public function __construct($caption, $name, $include_anon = false, $value = null, $size = 1, $multiple = false)
46  {
48  $limit = 200;
49  $select_element = new Select('', $name, $value, $size, $multiple);
50  if ($include_anon) {
51  $select_element->addOption(0, $xoops->getConfig('anonymous'));
52  }
53  $member_handler = $xoops->getHandlerMember();
54  $user_count = $member_handler->getUserCount();
55  $value = is_array($value) ? $value : (empty($value) ? array() : array($value));
56  if ($user_count > $limit && count($value) > 0) {
57  $criteria = new CriteriaCompo(new Criteria('uid', '(' . implode(',', $value) . ')', 'IN'));
58  } else {
59  $criteria = new CriteriaCompo();
60  $criteria->setLimit($limit);
61  }
62  $criteria->setSort('uname');
63  $criteria->setOrder('ASC');
64  $users = $member_handler->getUserList($criteria);
65  $select_element->addOptionArray($users);
66  if ($user_count <= $limit) {
67  parent::__construct($caption, "", $name);
68  $this->addElement($select_element);
69  return;
70  }
71 
72  $js_addusers = "<script type='text/javascript'>
73  function addusers(opts){
74  var num = opts.substring(0, opts.indexOf(':'));
75  opts = opts.substring(opts.indexOf(':')+1, opts.length);
76  var sel = xoopsGetElementById('" . $name . "');
77  var arr = new Array(num);
78  for (var n=0; n < num; n++) {
79  var nm = opts.substring(0, opts.indexOf(':'));
80  opts = opts.substring(opts.indexOf(':')+1, opts.length);
81  var val = opts.substring(0, opts.indexOf(':'));
82  opts = opts.substring(opts.indexOf(':')+1, opts.length);
83  var txt = opts.substring(0, nm - val.length);
84  opts = opts.substring(nm - val.length, opts.length);
85  var added = false;
86  for (var k = 0; k < sel.options.length; k++) {
87  if(sel.options[k].value == val){
88  added = true;
89  break;
90  }
91  }
92  if (added == false) {
93  sel.options[k] = new Option(txt, val);
94  sel.options[k].selected = true;
95  }
96  }
97  return true;
98  }
99  </script>";
100  $token = $xoops->security()->createToken();
101  $action_tray = new ElementTray("", " | ");
102  $action_tray->addElement(
103  new Label(
104  '',
105  '<a href="#" onclick="var sel = xoopsGetElementById(\'' . $name
106  . '\');for (var i = sel.options.length-1; i >= 0; i--) {if (!sel.options[i].selected) '
107  .'{sel.options[i] = null;}}; return false;">' . \XoopsLocale::REMOVE_UNSELECTED_USERS . "</a>"
108  )
109  );
110  $action_tray->addElement(
111  new Label(
112  '',
113  '<a href="#" onclick="openWithSelfMain(\'' . \XoopsBaseConfig::get('url') . '/include/findusers.php?target='
114  . $name . '&amp;multiple=' . $multiple . '&amp;token=' . $token
115  . '\', \'userselect\', 800, 600, null); return false;" >'
116  . \XoopsLocale::SEARCH_USERS . "</a>" . $js_addusers
117  )
118  );
119  parent::__construct($caption, '<br /><br />', $name);
120  $this->addElement($select_element);
121  $this->addElement($action_tray);
122  }
123 }
if($uname== ''||$pass== '') $member_handler
Definition: checklogin.php:44
static getInstance()
Definition: Xoops.php:160
const SEARCH_USERS
Definition: en_US.php:968
$xoops
Definition: admin.php:25
static get($name)
addElement(Element $formElement, $required=false)
Definition: ElementTray.php:80
__construct($caption, $name, $include_anon=false, $value=null, $size=1, $multiple=false)
Definition: SelectUser.php:45
$limit
Definition: findusers.php:202
$criteria