XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
formselectuser.php
Go to the documentation of this file.
1 <?php
22 defined('XOOPS_ROOT_PATH') or die('Restricted access');
23 
26 
30 class XoopsFormSelectUser extends XoopsFormElementTray
31 {
43  function XoopsFormSelectUser($caption, $name, $include_anon = false, $value = null, $size = 1, $multiple = false)
44  {
45  $limit = 200;
46  $select_element = new XoopsFormSelect('', $name, $value, $size, $multiple);
47  if ($include_anon) {
48  $select_element->addOption(0, $GLOBALS['xoopsConfig']['anonymous']);
49  }
50  $member_handler =& xoops_gethandler('member');
51  $user_count = $member_handler->getUserCount();
52  $value = is_array($value) ? $value : (empty($value) ? array() : array($value));
53  if ($user_count > $limit && count($value) > 0) {
54  $criteria = new CriteriaCompo(new Criteria('uid', '(' . implode(',', $value) . ')', 'IN'));
55  } else {
56  $criteria = new CriteriaCompo();
57  $criteria->setLimit($limit);
58  }
59  $criteria->setSort('uname');
60  $criteria->setOrder('ASC');
61  $users = $member_handler->getUserList($criteria);
62  $select_element->addOptionArray($users);
63  if ($user_count <= $limit) {
64  $this->XoopsFormElementTray($caption, "", $name);
65  $this->addElement($select_element);
66  return;
67  }
68 
69  xoops_loadLanguage('findusers');
70  $js_addusers = "<script type='text/javascript'>
71  function addusers(opts){
72  var num = opts.substring(0, opts.indexOf(':'));
73  opts = opts.substring(opts.indexOf(':')+1, opts.length);
74  var sel = xoopsGetElementById('" . $name . "');
75  var arr = new Array(num);
76  for (var n=0; n < num; n++) {
77  var nm = opts.substring(0, opts.indexOf(':'));
78  opts = opts.substring(opts.indexOf(':')+1, opts.length);
79  var val = opts.substring(0, opts.indexOf(':'));
80  opts = opts.substring(opts.indexOf(':')+1, opts.length);
81  var txt = opts.substring(0, nm - val.length);
82  opts = opts.substring(nm - val.length, opts.length);
83  var added = false;
84  for (var k = 0; k < sel.options.length; k++) {
85  if(sel.options[k].value == val){
86  added = true;
87  break;
88  }
89  }
90  if (added == false) {
91  sel.options[k] = new Option(txt, val);
92  sel.options[k].selected = true;
93  }
94  }
95  return true;
96  }
97  </script>";
98  $token = $GLOBALS['xoopsSecurity']->createToken();
99  $action_tray = new XoopsFormElementTray("", " | ");
100  $action_tray->addElement(new XoopsFormLabel('', '<a href="#" onclick="var sel = xoopsGetElementById(\'' . $name . '\');for (var i = sel.options.length-1; i >= 0; i--) {if (!sel.options[i].selected) {sel.options[i] = null;}}; return false;">' . _MA_USER_REMOVE . "</a>"));
101  $action_tray->addElement(new XoopsFormLabel('', '<a href="#" onclick="openWithSelfMain(\'' . XOOPS_URL . '/include/findusers.php?target=' . $name . '&amp;multiple=' . $multiple . '&amp;token=' . $token . '\', \'userselect\', 800, 600, null); return false;" >' . _MA_USER_MORE . "</a>" . $js_addusers));
102  $this->XoopsFormElementTray($caption, '<br /><br />', $name);
103  $this->addElement($select_element);
104  $this->addElement($action_tray);
105  }
106 }
107 
108 ?>