/** * Constructor * * @param string $form the form calling the editor selection * @param string $name editor name * @param string $value Pre-selected text value * @param bool $nohtml * @param array $allowed_editors * */ public function __construct($form, $name = 'editor', $value = null, $nohtml = false, $allowed_editors = array()) { parent::__construct(_SELECT); $this->allowed_editors = $allowed_editors; $this->form = $form; $this->name = $name; $this->value = $value; $this->nohtml = $nohtml; }
/** * XoopsFormDateTime::XoopsFormDateTime() * * @param mixed $caption form field caption * @param mixed $name form variable name * @param integer $size size of date select * @param integer $value unix timestamp, defaults to now * @param mixed $showtime control display of date and time elements * SHOW_BOTH, true - show both date and time selectors * SHOW_DATE, false - only show date selector * SHOW_TIME - only show time selector */ public function __construct($caption, $name, $size = 15, $value = 0, $showtime = true) { parent::__construct($caption, ' '); switch ((int) $showtime) { case static::SHOW_DATE: $displayDate = true; $displayTime = false; break; case static::SHOW_TIME: $displayDate = false; $displayTime = true; break; default: $displayDate = true; $displayTime = true; break; } $value = (int) $value; $value = $value > 0 ? $value : time(); $datetime = getdate($value); if ($displayDate) { $this->addElement(new XoopsFormTextDateSelect('', $name . '[date]', $size, $value)); } else { $value = !is_numeric($value) ? time() : (int) $value; $value = $value == 0 ? time() : $value; $displayValue = date(_SHORTDATESTRING, $value); $this->addElement(new XoopsFormHidden($name . '[date]', $displayValue)); } if ($displayTime) { $timearray = array(); for ($i = 0; $i < 24; ++$i) { for ($j = 0; $j < 60; $j += 10) { $key = $i * 3600 + $j * 60; $timearray[$key] = $j != 0 ? $i . ':' . $j : $i . ':0' . $j; } } ksort($timearray); $timeselect = new XoopsFormSelect('', $name . '[time]', $datetime['hours'] * 3600 + 600 * ceil($datetime['minutes'] / 10)); $timeselect->addOptionArray($timearray); $this->addElement($timeselect); } else { $this->addElement(new XoopsFormHidden($name . '[time]', 0)); } }
public function __construct($caption, $name, $size = 15, $value = 0) { parent::__construct($caption, ' '); $value = intval($value); $value = $value > 0 ? $value : time(); $datetime = getDate($value); $this->addElement(new XoopsFormTextDateSelect('', $name . '[date]', $size, $value)); $timearray = array(); for ($i = 0; $i < 24; $i++) { for ($j = 0; $j < 60; $j = $j + 10) { $key = $i * 3600 + $j * 60; $timearray[$key] = $j != 0 ? $i . ':' . $j : $i . ':0' . $j; } } ksort($timearray); $timeselect = new XoopsFormSelect('', $name . '[time]', $datetime['hours'] * 3600 + 600 * floor($datetime['minutes'] / 10)); $timeselect->addOptionArray($timearray); $this->addElement($timeselect); }
/** * @param $caption * @param $name * @param int $size * @param int $value * @param bool $showtime * @param bool $formatTimestamp */ public function __construct($caption, $name, $size = 15, $value = 0, $showtime = true, $formatTimestamp = true) { parent::__construct($caption, ' '); $value = (int) $value; $value = $value > 0 ? $value : time(); if ($formatTimestamp) { $value = strtotime(formatTimestamp($value)); } $datetime = getdate($value); $this->addElement(new XoopsFormTextDateSelect('', $name . '[date]', $size, $value, $showtime)); $timearray = array(); for ($i = 0; $i < 24; ++$i) { for ($j = 0; $j < 60; $j += 10) { $key = $i * 3600 + $j * 60; $timearray[$key] = $j != 0 ? $i . ':' . $j : $i . ':0' . $j; } } ksort($timearray); $timeselect = new XoopsFormSelect('', $name . '[time]', $datetime['hours'] * 3600 + 600 * floor($datetime['minutes'] / 10)); $timeselect->addOptionArray($timearray); $this->addElement($timeselect); }
/** * Constructor * * @param string $caption form element caption * @param string $name form element name * @param bool $includeAnonymous Include user "anonymous"? * @param mixed $value Pre-selected value (or array of them). * For an item with massive members, such as "Registered Users", "$value" * should be used to store selected temporary users only instead of all * members of that item * @param int $size Number or rows. "1" makes a drop-down-list. * @param bool $multiple Allow multiple selections? */ public function __construct($caption, $name, $includeAnonymous = false, $value = null, $size = 1, $multiple = false) { /** * @var mixed array|false - cache any result for this session. * Some modules use multiple copies of this element on a single page, so this call will * be made multiple times. This is only used when $value is null. * @todo this should be replaced with better interface, with autocomplete style search * and user specific MRU cache */ static $queryCache = false; /** * @var int - limit to this many rows */ $limit = 200; /** * @var string - cache time to live - will be interpreted by strtotime() */ $cachettl = '+5 minutes'; /** * @var string - cache key */ $cachekey = 'formselectuser'; $select_element = new XoopsFormSelect('', $name, $value, $size, $multiple); if ($includeAnonymous) { $select_element->addOption(0, $GLOBALS['xoopsConfig']['anonymous']); } $member_handler = xoops_getHandler('member'); $value = is_array($value) ? $value : (empty($value) ? array() : array($value)); $selectedUsers = array(); if (count($value) > 0) { // fetch the set of uids in $value $criteria = new Criteria('uid', '(' . implode(',', $value) . ')', 'IN'); $criteria->setSort('uname'); $criteria->setOrder('ASC'); $selectedUsers = $member_handler->getUserList($criteria); } // get the full selection list // we will always cache this version to reduce expense if (empty($queryCache)) { XoopsLoad::load('XoopsCache'); $queryCache = XoopsCache::read($cachekey); if ($queryCache === false) { $criteria = new CriteriaCompo(); if ($limit <= $member_handler->getUserCount()) { // if we have more than $limit users, we will select who to show based on last_login $criteria->setLimit($limit); $criteria->setSort('last_login'); $criteria->setOrder('DESC'); } else { $criteria->setSort('uname'); $criteria->setOrder('ASC'); } $queryCache = $member_handler->getUserList($criteria); asort($queryCache); XoopsCache::write($cachekey, $queryCache, $cachettl); // won't do anything different if write fails } } // merge with selected $users = $selectedUsers + $queryCache; $select_element->addOptionArray($users); if ($limit > count($users)) { parent::__construct($caption, '', $name); $this->addElement($select_element); return null; } xoops_loadLanguage('findusers'); $js_addusers = "<script type='text/javascript'>\n function addusers(opts)\n {\n var num = opts.substring(0, opts.indexOf(':'));\n opts = opts.substring(opts.indexOf(':')+1, opts.length);\n var sel = xoopsGetElementById('" . $name . "');\n var arr = new Array(num);\n for (var n=0; n < num; n++) {\n var nm = opts.substring(0, opts.indexOf(':'));\n opts = opts.substring(opts.indexOf(':')+1, opts.length);\n var val = opts.substring(0, opts.indexOf(':'));\n opts = opts.substring(opts.indexOf(':')+1, opts.length);\n var txt = opts.substring(0, nm - val.length);\n opts = opts.substring(nm - val.length, opts.length);\n var added = false;\n for (var k = 0; k < sel.options.length; k++) {\n if (sel.options[k].value == val) {\n added = true;\n break;\n }\n }\n if (added == false) {\n sel.options[k] = new Option(txt, val);\n sel.options[k].selected = true;\n }\n }\n\n return true;\n }\n </script>"; $token = $GLOBALS['xoopsSecurity']->createToken(); $action_tray = new XoopsFormElementTray('', ' | '); $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>')); $action_tray->addElement(new XoopsFormLabel('', '<a href="#" onclick="openWithSelfMain(\'' . XOOPS_URL . '/include/findusers.php?target=' . $name . '&multiple=' . $multiple . '&token=' . $token . '\', \'userselect\', 800, 600, null); return false;" >' . _MA_USER_MORE . '</a>' . $js_addusers)); parent::__construct($caption, '<br><br>', $name); $this->addElement($select_element); $this->addElement($action_tray); }