示例#1
0
 /**
  * Constructor
  *
  * @param    string    $caption
  * @param    string    $name
  * @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    bool    $include_anon    Include user "anonymous"?
  * @param    int        $size            Number or rows. "1" makes a drop-down-list.
  * @param    bool    $multiple       Allow multiple selections?
  */
 function __construct($caption, $name, $include_anon = false, $value = null, $size = 1, $multiple = false)
 {
     $limit = 200;
     $select_element = new Xmf_Form_Element_Select("", $name, $value, $size, $multiple);
     if ($include_anon) {
         $select_element->addOption(0, $GLOBALS["xoopsConfig"]['anonymous']);
     }
     $member_handler =& xoops_gethandler('member');
     $user_count = $member_handler->getUserCount();
     $value = is_array($value) ? $value : (empty($value) ? array() : array($value));
     if ($user_count > $limit && count($value) > 0) {
         $criteria = new CriteriaCompo(new Criteria("uid", "(" . implode(",", $value) . ")", "IN"));
     } else {
         $criteria = new CriteriaCompo();
         $criteria->setLimit($limit);
     }
     $criteria->setSort('uname');
     $criteria->setOrder('ASC');
     $users = $member_handler->getUserList($criteria);
     $select_element->addOptionArray($users);
     if ($user_count <= $limit) {
         parent::__construct($caption, "", $name);
         $this->addElement($select_element);
         return;
     }
     xoops_loadLanguage("findusers");
     $js_addusers = "<script type=\"text/javascript\">\r\n            function addusers(opts){\r\n                var num = opts.substring(0, opts.indexOf(\":\"));\r\n                opts = opts.substring(opts.indexOf(\":\")+1, opts.length);\r\n                var sel = xoopsGetElementById(\"" . $name . ($multiple ? "[]" : "") . "\");\r\n                var arr = new Array(num);\r\n                for (var n=0; n < num; n++) {\r\n                    var nm = opts.substring(0, opts.indexOf(\":\"));\r\n                    opts = opts.substring(opts.indexOf(\":\")+1, opts.length);\r\n                    var val = opts.substring(0, opts.indexOf(\":\"));\r\n                    opts = opts.substring(opts.indexOf(\":\")+1, opts.length);\r\n                    var txt = opts.substring(0, nm - val.length);\r\n                    opts = opts.substring(nm - val.length, opts.length);\r\n                    var added = false;\r\n                    for (var k = 0; k < sel.options.length; k++) {\r\n                        if(sel.options[k].value == val){\r\n                            added = true;\r\n                            break;\r\n                        }\r\n                    }\r\n                    if (added == false) {\r\n                        sel.options[k] = new Option(txt, val);\r\n                        sel.options[k].selected = true;\r\n                    }\r\n                }\r\n                return true;\r\n            }\r\n            </script>";
     $token = $GLOBALS['xoopsSecurity']->createToken();
     $action_tray = new Xmf_Form_Element_Tray("", " | ");
     $action_tray->addElement(new Xmf_Form_Element_Label('', "<a href='#' onclick='var sel = xoopsGetElementById(\"" . $name . ($multiple ? "[]" : "") . "\");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 Xmf_Form_Element_Label('', "<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));
     parent::__construct($caption, "<br /><br />", $name);
     $this->addElement($select_element);
     $this->addElement($action_tray);
 }
示例#2
0
    function render()
    {
        $editor_handler = Xmf_Form_Element_Editor_Handler::getInstance();
        $editor_handler->allowed_editors = $this->allowed_editors;
        $option_select = new Xmf_Form_Element_Select("", $this->name, $this->value);
        $extra = 'onchange="if(this.options[this.selectedIndex].value.length > 0 ){
			window.document.forms.' . $this->form->getName() . '.submit();
			}"';
        $option_select->setExtra($extra);
        $option_select->addOptionArray($editor_handler->getList($this->nohtml));
        $this->addElement($option_select);
        return parent::render();
    }
示例#3
0
 function __construct($caption, $name, $size = 15, $value = 0)
 {
     parent::__construct($caption, '&nbsp;');
     $value = intval($value);
     $value = $value > 0 ? $value : time();
     $datetime = getDate($value);
     $this->addElement(new Xmf_Form_Element_Text_DateSelect('', $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 Xmf_Form_Element_Select('', $name . '[time]', $datetime['hours'] * 3600 + 600 * ceil($datetime['minutes'] / 10));
     $timeselect->addOptionArray($timearray);
     $this->addElement($timeselect);
 }
示例#4
0
 /**
  * Get information for the theme select box
  *
  * @param	string  $key        key of the variables in the targetobject
  * @param	string  $var        key of the variables in the targetobject
  * @param	bool    $multiple   will you need a form element which shows multiple items
  */
 function getThemeSelect($key, $var, $multiple = false)
 {
     $size = $multiple ? 5 : 1;
     $theme_select = new Xmf_Form_Element_Select($var['title'], $key, $this->targetObject->getVar($key), $size, $multiple);
     $handle = opendir(XOOPS_THEME_PATH . '/');
     $dirlist = array();
     while (false !== ($file = readdir($handle))) {
         if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match("/^[.]{1,2}\$/", $file) && strtolower($file) != 'cvs') {
             $dirlist[$file] = $file;
         }
     }
     closedir($handle);
     if (!empty($dirlist)) {
         asort($dirlist);
         $theme_select->addOptionArray($dirlist);
     }
     return $theme_select;
 }