예제 #1
0
파일: search.php 프로젝트: RanLee/XoopsCore
 public function getSearchFrom($andor, $queries, $mids, $mid)
 {
     $xoops = Xoops::getInstance();
     $search = Search::getInstance();
     // create form
     parent::__construct(_MD_SEARCH, 'search', 'index.php', 'get');
     // create form elements
     $this->addElement(new Xoops\Form\Text(_MD_SEARCH_KEYWORDS, 'query', 30, 255, htmlspecialchars(stripslashes($this->queryArrayToString($queries)), ENT_QUOTES)), true);
     $type_select = new Xoops\Form\Select(_MD_SEARCH_TYPE, 'andor', $andor);
     $type_select->addOptionArray(array('AND' => _MD_SEARCH_ALL, 'OR' => _MD_SEARCH_ANY));
     $this->addElement($type_select);
     if (!empty($mids)) {
         $mods_checkbox = new Xoops\Form\Checkbox(_MD_SEARCH_SEARCHIN, 'mids[]', $mids);
     } else {
         $mods_checkbox = new Xoops\Form\Checkbox(_MD_SEARCH_SEARCHIN, 'mids[]', $mid);
     }
     if (empty($modules)) {
         $gperm_handler = $xoops->getHandlerGroupperm();
         $available_modules = $gperm_handler->getItemIds('module_read', $xoops->getUserGroups());
         $available_plugins = \Xoops\Module\Plugin::getPlugins('search');
         //todo, would be nice to have the module ids availabe also
         $criteria = new CriteriaCompo();
         $criteria->add(new Criteria('dirname', "('" . implode("','", array_keys($available_plugins)) . "')", 'IN'));
         if (isset($available_modules) && !empty($available_modules)) {
             $criteria->add(new Criteria('mid', '(' . implode(',', $available_modules) . ')', 'IN'));
         }
         $module_handler = $xoops->getHandlerModule();
         $mods_checkbox->addOptionArray($module_handler->getNameList($criteria));
     } else {
         /* @var $module XoopsModule */
         $module_array = array();
         foreach ($modules as $mid => $module) {
             $module_array[$mid] = $module->getVar('name');
         }
         $mods_checkbox->addOptionArray($module_array);
     }
     $this->addElement($mods_checkbox);
     if ($search->getConfig('keyword_min') > 0) {
         $this->addElement(new Xoops\Form\Label(_MD_SEARCH_SEARCHRULE, sprintf(_MD_SEARCH_KEYIGNORE, $search->getConfig('keyword_min'))));
     }
     $this->addElement(new Xoops\Form\Hidden('action', 'results'));
     $this->addElement(new Xoops\Form\Token('id'));
     $this->addElement(new Xoops\Form\Button('', 'submit', _MD_SEARCH, 'submit'));
     return $this;
 }
예제 #2
0
파일: group.php 프로젝트: RanLee/XoopsCore
 /**
  * __construct
  *
  * @param XoopsGroup|XoopsObject &$obj group object
  */
 public function __construct(XoopsGroup &$obj)
 {
     $xoops = Xoops::getInstance();
     if ($obj->isNew()) {
         $s_cat_value = '';
         $a_mod_value = array();
         $r_mod_value = array();
         $r_block_value = array();
     } else {
         $sysperm_handler = $xoops->getHandlerGroupperm();
         $s_cat_value = $sysperm_handler->getItemIds('system_admin', $obj->getVar('groupid'));
         $member_handler = $xoops->getHandlerMember();
         $thisgroup = $member_handler->getGroup($obj->getVar('groupid'));
         $moduleperm_handler = $xoops->getHandlerGroupperm();
         $a_mod_value = $moduleperm_handler->getItemIds('module_admin', $thisgroup->getVar('groupid'));
         $r_mod_value = $moduleperm_handler->getItemIds('module_read', $thisgroup->getVar('groupid'));
         $gperm_handler = $xoops->getHandlerGroupperm();
         $r_block_value = $gperm_handler->getItemIds('block_read', $obj->getVar('groupid'));
     }
     include_once $xoops->path('/modules/system/constants.php');
     $title = $obj->isNew() ? SystemLocale::ADD_NEW_GROUP : SystemLocale::EDIT_GROUP;
     parent::__construct($title, "groupform", 'admin.php', "post", true);
     $this->setExtra('enctype="multipart/form-data"');
     $name_text = new Xoops\Form\Text(SystemLocale::GROUP_NAME, "name", 4, 50, $obj->getVar('name'));
     $desc_text = new Xoops\Form\TextArea(SystemLocale::GROUP_DESCRIPTION, "desc", $obj->getVar('description'));
     $system_catids = new Xoops\Form\ElementTray(SystemLocale::SYSTEM_ADMIN_RIGHTS, '');
     $s_cat_checkbox_all = new Xoops\Form\Checkbox('', "catbox", 1);
     $s_cat_checkbox_all->addOption('allbox', XoopsLocale::ALL);
     $s_cat_checkbox_all->setExtra(" onclick='xoopsCheckGroup(\"groupform\", \"catbox\" , \"system_catids[]\");' ");
     $s_cat_checkbox_all->setClass('xo-checkall');
     $system_catids->addElement($s_cat_checkbox_all);
     $s_cat_checkbox = new Xoops\Form\Checkbox('', "system_catids", $s_cat_value);
     //$s_cat_checkbox->columns = 6;
     $admin_dir = \XoopsBaseConfig::get('root-path') . '/modules/system/admin/';
     $dirlist = XoopsLists::getDirListAsArray($admin_dir);
     foreach ($dirlist as $file) {
         include \XoopsBaseConfig::get('root-path') . '/modules/system/admin/' . $file . '/xoops_version.php';
         if (!empty($modversion['category'])) {
             if ($xoops->getModuleConfig('active_' . $file, 'system') == 1) {
                 $s_cat_checkbox->addOption($modversion['category'], $modversion['name']);
             }
         }
         unset($modversion);
     }
     unset($dirlist);
     $system_catids->addElement($s_cat_checkbox);
     $admin_mids = new Xoops\Form\ElementTray(SystemLocale::MODULE_ADMIN_RIGHTS, '');
     $s_admin_checkbox_all = new Xoops\Form\Checkbox('', "adminbox", 1);
     $s_admin_checkbox_all->addOption('allbox', XoopsLocale::ALL);
     $s_admin_checkbox_all->setExtra(" onclick='xoopsCheckGroup(\"groupform\", \"adminbox\" , \"admin_mids[]\");' ");
     $s_admin_checkbox_all->setClass('xo-checkall');
     $admin_mids->addElement($s_admin_checkbox_all);
     $a_mod_checkbox = new Xoops\Form\Checkbox('', "admin_mids[]", $a_mod_value);
     //$a_mod_checkbox->columns = 5;
     $module_handler = $xoops->getHandlerModule();
     $criteria = new CriteriaCompo(new Criteria('hasadmin', 1));
     $criteria->add(new Criteria('isactive', 1));
     $criteria->add(new Criteria('dirname', 'system', '<>'));
     $a_mod_checkbox->addOptionArray($module_handler->getNameList($criteria));
     $admin_mids->addElement($a_mod_checkbox);
     $read_mids = new Xoops\Form\ElementTray(SystemLocale::MODULE_ACCESS_RIGHTS, '');
     $s_mod_checkbox_all = new Xoops\Form\Checkbox('', "readbox", 1);
     $s_mod_checkbox_all->addOption('allbox', XoopsLocale::ALL);
     $s_mod_checkbox_all->setExtra(" onclick='xoopsCheckGroup(\"groupform\", \"readbox\" , \"read_mids[]\");' ");
     $s_mod_checkbox_all->setClass('xo-checkall');
     $read_mids->addElement($s_mod_checkbox_all);
     $r_mod_checkbox = new Xoops\Form\Checkbox('', "read_mids[]", $r_mod_value);
     //$r_mod_checkbox->columns = 5;
     $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
     $criteria->add(new Criteria('isactive', 1));
     $r_mod_checkbox->addOptionArray($module_handler->getNameList($criteria));
     $read_mids->addElement($r_mod_checkbox);
     $criteria = new CriteriaCompo(new Criteria('isactive', 1));
     $criteria->setSort("mid");
     $criteria->setOrder("ASC");
     $module_list = $module_handler->getNameList($criteria);
     $module_list[0] = SystemLocale::CUSTOM_BLOCK;
     $block_handler = $xoops->getHandlerBlock();
     $blocks_obj = $block_handler->getDistinctObjects(new Criteria("mid", "('" . implode("', '", array_keys($module_list)) . "')", "IN"), true);
     $blocks_module = array();
     foreach (array_keys($blocks_obj) as $bid) {
         $title = $blocks_obj[$bid]->getVar("title");
         $blocks_module[$blocks_obj[$bid]->getVar('mid')][$blocks_obj[$bid]->getVar('bid')] = empty($title) ? $blocks_obj[$bid]->getVar("name") : $title;
     }
     ksort($blocks_module);
     $r_block_tray = new Xoops\Form\ElementTray(SystemLocale::BLOCK_ACCESS_RIGHTS, "<br /><br />");
     $s_checkbox_all = new Xoops\Form\Checkbox('', "blocksbox", 1);
     $s_checkbox_all->addOption('allbox', XoopsLocale::ALL);
     $s_checkbox_all->setExtra(" onclick='xoopsCheckGroup(\"groupform\", \"blocksbox\" , \"read_bids[]\");' ");
     $s_checkbox_all->setClass('xo-checkall');
     $r_block_tray->addElement($s_checkbox_all);
     foreach (array_keys($blocks_module) as $mid) {
         $new_blocks_array = array();
         foreach ($blocks_module[$mid] as $key => $value) {
             $new_blocks_array[$key] = "<a href='" . \XoopsBaseConfig::get('url') . "/modules/system/admin.php?fct=blocksadmin&amp;op=edit&amp;bid={$key}' " . "title='ID: {$key}' rel='external'>{$value}</a>";
         }
         $r_block_checkbox = new Xoops\Form\Checkbox('<strong>' . $module_list[$mid] . '</strong><br />', "read_bids[]", $r_block_value);
         //$r_block_checkbox->columns = 5;
         $r_block_checkbox->addOptionArray($new_blocks_array);
         $r_block_tray->addElement($r_block_checkbox);
         unset($r_block_checkbox);
     }
     if (!$obj->isNew()) {
         $this->addElement(new Xoops\Form\Hidden('g_id', $obj->getVar('groupid')));
         $this->addElement(new Xoops\Form\Hidden("op", "groups_save_update"));
     } else {
         $this->addElement(new Xoops\Form\Hidden("op", "groups_save_add"));
     }
     $this->addElement(new Xoops\Form\Hidden('fct', 'groups'));
     $this->addElement($name_text, true);
     $this->addElement($desc_text);
     $this->addElement($system_catids);
     $this->addElement($admin_mids);
     $this->addElement($read_mids);
     $this->addElement($r_block_tray);
     $this->addElement(new Xoops\Form\Button("", "submit", XoopsLocale::A_SUBMIT, "submit"));
 }
예제 #3
0
 /**
  * @param PagePage_content|XoopsObject $obj
  */
 public function __construct(PagePage_content $obj)
 {
     $helper = Page::getInstance();
     $xoops = $helper->xoops();
     $xoops->theme()->addStylesheet('modules/page/css/styles.css');
     $title = $obj->isNew() ? PageLocale::A_ADD_CONTENT : PageLocale::A_EDIT_CONTENT;
     parent::__construct($title, 'form', 'content.php', 'post', true, 'raw');
     $tabTray = new Xoops\Form\TabTray('', 'uniqueid');
     /**
      * Main
      */
     $tab1 = new Xoops\Form\Tab(PageLocale::TAB_MAIN, 'main');
     //Author
     //        if ($helper->isUserAdmin()) {
     $content_author = $obj->isNew() ? $xoops->user->getVar('uid') : $obj->getVar('content_author');
     $tab1->addElement(new Xoops\Form\SelectUser(XoopsLocale::AUTHOR, 'content_author', true, $content_author, 1, false), true);
     //        }
     //date
     $tab1->addElement(new Xoops\Form\DateTime(XoopsLocale::DATE, 'content_create', $obj->getVar('content_create')));
     //title
     $tab1->addElement(new Xoops\Form\Text(XoopsLocale::TITLE, 'content_title', 12, 255, $obj->getVar('content_title'), ''), true);
     // editor
     $editor_configs = array();
     $editor_configs['editor'] = $helper->getConfig('page_editor');
     $editor_configs['rows'] = 12;
     $editor_configs['cols'] = 12;
     //short text
     $editor_configs['name'] = 'content_shorttext';
     $editor_configs['value'] = $obj->getVar('content_shorttext', 'e');
     $tab1->addElement(new Xoops\Form\Editor(XoopsLocale::SHORT_TEXT, 'content_shorttext', $editor_configs), true);
     //text
     $editor_configs['name'] = 'content_text';
     $editor_configs['value'] = $obj->getVar('content_text', 'e');
     $text = new Xoops\Form\Editor(XoopsLocale::TEXT, 'content_text', $editor_configs);
     $text->setDescription(PageLocale::CONTENT_TEXT_DESC);
     $tab1->addElement($text, false);
     //Weight
     $weight = new Xoops\Form\Text(XoopsLocale::WEIGHT, 'content_weight', 1, 5, $obj->getVar('content_weight'), '');
     $weight->setPattern('^\\d+$', PageLocale::E_WEIGHT);
     $tab1->addElement($weight, true);
     $tabTray->addElement($tab1);
     /**
      * Metas
      */
     $tab2 = new Xoops\Form\Tab(PageLocale::TAB_METAS, 'metas');
     //content_mkeyword
     $tab2->addElement(new Xoops\Form\TextArea(PageLocale::CONTENT_META_KEYWORDS, 'content_mkeyword', $obj->getVar('content_mkeyword'), 1, 11, PageLocale::CONTENT_META_KEYWORDS_DSC));
     //content_mdescription
     $tab2->addElement(new Xoops\Form\TextArea(PageLocale::CONTENT_META_DESCRIPTION, 'content_mdescription', $obj->getVar('content_mdescription'), 5, 11));
     $tabTray->addElement($tab2);
     /**
      * Options
      */
     $tab3 = new Xoops\Form\Tab(PageLocale::TAB_OPTIONS, 'options');
     //Options
     $content_option = $obj->getOptions();
     $checkbox = new Xoops\Form\Checkbox(XoopsLocale::OPTIONS, 'content_option', $content_option, false);
     $checkbox->setDescription(PageLocale::CONTENT_OPTIONS_DSC);
     foreach ($obj->options as $option) {
         $checkbox->addOption($option, \Xoops\Locale::translate('L_CONTENT_DO' . strtoupper($option), 'page'));
     }
     $tab3->addElement($checkbox);
     //maindisplay
     $tab3->addElement(new Xoops\Form\RadioYesNo(PageLocale::Q_ON_MAIN_PAGE, 'content_maindisplay', $obj->getVar('content_maindisplay')));
     //active
     $tab3->addElement(new Xoops\Form\RadioYesNo(XoopsLocale::ACTIVE, 'content_status', $obj->getVar('content_status')));
     $tabTray->addElement($tab3);
     /**
      * Permissions
      */
     if ($helper->isUserAdmin()) {
         $tab4 = new Xoops\Form\Tab(PageLocale::TAB_PERMISSIONS, 'permissions');
         //permissions
         $group_list = $xoops->getHandlerMember()->getGroupList();
         $full_list = array_keys($group_list);
         if (!$obj->isNew()) {
             $module_id = $helper->getModule()->getVar('mid', 'n');
             $groups_ids_view = $helper->getGrouppermHandler()->getGroupIds('page_view_item', $obj->getVar('content_id'), $module_id);
             $groups_ids_view = array_values($groups_ids_view);
             $groups_can_view_checkbox = new Xoops\Form\Checkbox(PageLocale::CONTENT_SELECT_GROUPS, 'groups_view_item[]', $groups_ids_view, false);
         } else {
             $groups_can_view_checkbox = new Xoops\Form\Checkbox(PageLocale::CONTENT_SELECT_GROUPS, 'groups_view_item[]', $full_list, false);
         }
         $groups_can_view_checkbox->addOptionArray($group_list);
         $tab4->addElement($groups_can_view_checkbox);
         $tabTray->addElement($tab4);
     }
     $this->addElement($tabTray);
     $this->addElement(new Xoops\Form\Hidden('content_id', $obj->getVar('content_id')));
     /**
      * Buttons
      */
     $buttonTray = new Xoops\Form\ElementTray('', '');
     $buttonTray->addElement(new Xoops\Form\Hidden('op', 'save'));
     $buttonSubmit = new Xoops\Form\Button('', 'submit', XoopsLocale::A_SUBMIT, 'submit');
     $buttonSubmit->setClass('btn btn-success');
     $buttonTray->addElement($buttonSubmit);
     $buttonReset = new Xoops\Form\Button('', 'reset', XoopsLocale::A_RESET, 'reset');
     $buttonReset->setClass('btn btn-warning');
     $buttonTray->addElement($buttonReset);
     $buttonCancel = new Xoops\Form\Button('', 'cancel', XoopsLocale::A_CANCEL, 'button');
     $buttonCancel->setExtra("onclick='javascript:history.go(-1);'");
     $buttonCancel->setClass('btn btn-danger');
     $buttonTray->addElement($buttonCancel);
     $this->addElement($buttonTray);
 }
예제 #4
0
파일: field.php 프로젝트: RanLee/XoopsCore
 /**
  * @param ProfileField|XoopsObject $obj
  */
 public function __construct(ProfileField $obj)
 {
     $xoops = Xoops::getInstance();
     $title = $obj->isNew() ? sprintf(_PROFILE_AM_ADD, _PROFILE_AM_FIELD) : sprintf(_PROFILE_AM_EDIT, _PROFILE_AM_FIELD);
     parent::__construct($title, 'form', '', 'post', true);
     $this->addElement(new Xoops\Form\Text(_PROFILE_AM_TITLE, 'field_title', 5, 255, $obj->getVar('field_title', 'e')), true);
     $this->addElement(new Xoops\Form\TextArea(_PROFILE_AM_DESCRIPTION, 'field_description', $obj->getVar('field_description', 'e'), 5, 5));
     if (!$obj->isNew()) {
         $fieldcat_id = $obj->getVar('cat_id');
     } else {
         $fieldcat_id = 0;
     }
     $category_handler = $xoops->getModuleHandler('category');
     $cat_select = new Xoops\Form\Select(_PROFILE_AM_CATEGORY, 'field_category', $fieldcat_id);
     $cat_select->addOption(0, _PROFILE_AM_DEFAULT);
     $cat_select->addOptionArray($category_handler->getList());
     $this->addElement($cat_select);
     $weight = new Xoops\Form\Text(_PROFILE_AM_WEIGHT, 'field_weight', 1, 10, $obj->getVar('field_weight', 'e'), '');
     $weight->setPattern('^\\d+$', _PROFILE_AM_ERROR_WEIGHT);
     $this->addElement($weight, true);
     if ($obj->getVar('field_config') || $obj->isNew()) {
         if (!$obj->isNew()) {
             $this->addElement(new Xoops\Form\Label(_PROFILE_AM_NAME, $obj->getVar('field_name')));
             $this->addElement(new Xoops\Form\Hidden('id', $obj->getVar('field_id')));
         } else {
             $this->addElement(new Xoops\Form\Text(_PROFILE_AM_NAME, 'field_name', 5, 255, $obj->getVar('field_name', 'e')), true);
         }
         //autotext and theme left out of this one as fields of that type should never be changed (valid assumption, I think)
         $fieldtypes = array('checkbox' => _PROFILE_AM_CHECKBOX, 'date' => _PROFILE_AM_DATE, 'datetime' => _PROFILE_AM_DATETIME, 'longdate' => _PROFILE_AM_LONGDATE, 'group' => _PROFILE_AM_GROUP, 'group_multi' => _PROFILE_AM_GROUPMULTI, 'language' => _PROFILE_AM_LANGUAGE, 'radio' => _PROFILE_AM_RADIO, 'select' => _PROFILE_AM_SELECT, 'select_multi' => _PROFILE_AM_SELECTMULTI, 'textarea' => _PROFILE_AM_TEXTAREA, 'dhtml' => _PROFILE_AM_DHTMLTEXTAREA, 'textbox' => _PROFILE_AM_TEXTBOX, 'timezone' => _PROFILE_AM_TIMEZONE, 'yesno' => _PROFILE_AM_YESNO);
         $element_select = new Xoops\Form\Select(_PROFILE_AM_TYPE, 'field_type', $obj->getVar('field_type', 'e'));
         $element_select->addOptionArray($fieldtypes);
         $this->addElement($element_select);
         switch ($obj->getVar('field_type')) {
             case "textbox":
                 $valuetypes = array(XOBJ_DTYPE_ARRAY => _PROFILE_AM_ARRAY, XOBJ_DTYPE_EMAIL => _PROFILE_AM_EMAIL, XOBJ_DTYPE_INT => _PROFILE_AM_INT, XOBJ_DTYPE_FLOAT => _PROFILE_AM_FLOAT, XOBJ_DTYPE_DECIMAL => _PROFILE_AM_DECIMAL, XOBJ_DTYPE_TXTAREA => _PROFILE_AM_TXTAREA, XOBJ_DTYPE_TXTBOX => _PROFILE_AM_TXTBOX, XOBJ_DTYPE_URL => _PROFILE_AM_URL, XOBJ_DTYPE_OTHER => _PROFILE_AM_OTHER);
                 $type_select = new Xoops\Form\Select(_PROFILE_AM_VALUETYPE, 'field_valuetype', $obj->getVar('field_valuetype', 'e'), 5, 5);
                 $type_select->addOptionArray($valuetypes);
                 $this->addElement($type_select);
                 break;
             case "select":
             case "radio":
                 $valuetypes = array(XOBJ_DTYPE_ARRAY => _PROFILE_AM_ARRAY, XOBJ_DTYPE_EMAIL => _PROFILE_AM_EMAIL, XOBJ_DTYPE_INT => _PROFILE_AM_INT, XOBJ_DTYPE_FLOAT => _PROFILE_AM_FLOAT, XOBJ_DTYPE_DECIMAL => _PROFILE_AM_DECIMAL, XOBJ_DTYPE_TXTAREA => _PROFILE_AM_TXTAREA, XOBJ_DTYPE_TXTBOX => _PROFILE_AM_TXTBOX, XOBJ_DTYPE_URL => _PROFILE_AM_URL, XOBJ_DTYPE_OTHER => _PROFILE_AM_OTHER);
                 $type_select = new Xoops\Form\Select(_PROFILE_AM_VALUETYPE, 'field_valuetype', $obj->getVar('field_valuetype', 'e'));
                 $type_select->addOptionArray($valuetypes);
                 $this->addElement($type_select);
                 break;
         }
         //$this->addElement(new Xoops\Form\RadioYesNo(_PROFILE_AM_NOTNULL, 'field_notnull', $obj->getVar('field_notnull', 'e') ));
         if ($obj->getVar('field_type') == "select" || $obj->getVar('field_type') == "select_multi" || $obj->getVar('field_type') == "radio" || $obj->getVar('field_type') == "checkbox") {
             $options = $obj->getVar('field_options');
             if (count($options) > 0) {
                 $remove_options = new Xoops\Form\Checkbox(_PROFILE_AM_REMOVEOPTIONS, 'removeOptions');
                 //$remove_options->columns = 3;
                 asort($options);
                 foreach (array_keys($options) as $key) {
                     $options[$key] .= "[{$key}]";
                 }
                 $remove_options->addOptionArray($options);
                 $this->addElement($remove_options);
             }
             $option_text = "<table  cellspacing='1'><tr><td class='width20'>" . _PROFILE_AM_KEY . "</td><td>" . _PROFILE_AM_VALUE . "</td></tr>";
             for ($i = 0; $i < 3; ++$i) {
                 $option_text .= "<tr><td><input type='text' name='addOption[{$i}][key]' id='addOption[{$i}][key]' size='15' /></td><td><input type='text' name='addOption[{$i}][value]' id='addOption[{$i}][value]' size='35' /></td></tr>";
                 $option_text .= "<tr height='3px'><td colspan='2'> </td></tr>";
             }
             $option_text .= "</table>";
             $this->addElement(new Xoops\Form\Label(_PROFILE_AM_ADDOPTION, $option_text));
         }
     }
     if ($obj->getVar('field_edit')) {
         switch ($obj->getVar('field_type')) {
             case "textbox":
             case "textarea":
             case "dhtml":
                 $this->addElement(new Xoops\Form\Text(_PROFILE_AM_MAXLENGTH, 'field_maxlength', 5, 5, $obj->getVar('field_maxlength', 'e')));
                 $this->addElement(new Xoops\Form\TextArea(_PROFILE_AM_DEFAULT, 'field_default', $obj->getVar('field_default', 'e')));
                 break;
             case "checkbox":
             case "select_multi":
                 $def_value = $obj->getVar('field_default', 'e') != null ? unserialize($obj->getVar('field_default', 'n')) : null;
                 $element = new Xoops\Form\Select(_PROFILE_AM_DEFAULT, 'field_default', $def_value, 8, true);
                 $options = $obj->getVar('field_options');
                 asort($options);
                 // If options do not include an empty element, then add a blank option to prevent any default selection
                 if (!in_array('', array_keys($options))) {
                     $element->addOption('', XoopsLocale::NONE);
                 }
                 $element->addOptionArray($options);
                 $this->addElement($element);
                 break;
             case "select":
             case "radio":
                 $def_value = $obj->getVar('field_default', 'e') != null ? $obj->getVar('field_default') : null;
                 $element = new Xoops\Form\Select(_PROFILE_AM_DEFAULT, 'field_default', $def_value);
                 $options = $obj->getVar('field_options');
                 asort($options);
                 // If options do not include an empty element, then add a blank option to prevent any default selection
                 if (!in_array('', array_keys($options))) {
                     $element->addOption('', XoopsLocale::NONE);
                 }
                 $element->addOptionArray($options);
                 $this->addElement($element);
                 break;
             case "date":
                 $this->addElement(new Xoops\Form\DateSelect(_PROFILE_AM_DEFAULT, 'field_default', 2, $obj->getVar('field_default', 'e')));
                 break;
             case "longdate":
                 $this->addElement(new Xoops\Form\DateSelect(_PROFILE_AM_DEFAULT, 'field_default', 2, strtotime($obj->getVar('field_default', 'e'))));
                 break;
             case "datetime":
                 $this->addElement(new Xoops\Form\DateTime(_PROFILE_AM_DEFAULT, 'field_default', 2, $obj->getVar('field_default', 'e')));
                 break;
             case "yesno":
                 $this->addElement(new Xoops\Form\RadioYesNo(_PROFILE_AM_DEFAULT, 'field_default', $obj->getVar('field_default', 'e')));
                 break;
             case "timezone":
                 $this->addElement(new Xoops\Form\SelectTimeZone(_PROFILE_AM_DEFAULT, 'field_default', $obj->getVar('field_default', 'e')));
                 break;
             case "language":
                 $this->addElement(new Xoops\Form\SelectLanguage(_PROFILE_AM_DEFAULT, 'field_default', $obj->getVar('field_default', 'e')));
                 break;
             case "group":
                 $this->addElement(new Xoops\Form\SelectGroup(_PROFILE_AM_DEFAULT, 'field_default', true, $obj->getVar('field_default', 'e')));
                 break;
             case "group_multi":
                 $this->addElement(new Xoops\Form\SelectGroup(_PROFILE_AM_DEFAULT, 'field_default', true, unserialize($obj->getVar('field_default', 'n')), 5, true));
                 break;
             case "theme":
                 $this->addElement(new Xoops\Form\SelectTheme(_PROFILE_AM_DEFAULT, 'field_default', $obj->getVar('field_default', 'e')));
                 break;
             case "autotext":
                 $this->addElement(new Xoops\Form\TextArea(_PROFILE_AM_DEFAULT, 'field_default', $obj->getVar('field_default', 'e')));
                 break;
         }
     }
     $groupperm_handler = $xoops->getHandlerGroupperm();
     $searchable_types = array('textbox', 'select', 'radio', 'yesno', 'date', 'datetime', 'timezone', 'language');
     if (in_array($obj->getVar('field_type'), $searchable_types)) {
         $search_groups = $groupperm_handler->getGroupIds('profile_search', $obj->getVar('field_id'), $xoops->module->getVar('mid'));
         $this->addElement(new Xoops\Form\SelectGroup(_PROFILE_AM_PROF_SEARCH, 'profile_search', true, $search_groups, 5, true));
     }
     if ($obj->getVar('field_edit') || $obj->isNew()) {
         if (!$obj->isNew()) {
             //Load groups
             $editable_groups = $groupperm_handler->getGroupIds('profile_edit', $obj->getVar('field_id'), $xoops->module->getVar('mid'));
         } else {
             $editable_groups = array();
         }
         $this->addElement(new Xoops\Form\SelectGroup(_PROFILE_AM_PROF_EDITABLE, 'profile_edit', false, $editable_groups, 5, true));
         $this->addElement(new Xoops\Form\RadioYesNo(_PROFILE_AM_REQUIRED, 'field_required', $obj->getVar('field_required', 'e')));
         $regstep_select = new Xoops\Form\Select(_PROFILE_AM_PROF_REGISTER, 'step_id', $obj->getVar('step_id', 'e'));
         $regstep_select->addOption(0, XoopsLocale::NO);
         $regstep_handler = $xoops->getModuleHandler('regstep');
         $regstep_select->addOptionArray($regstep_handler->getList());
         $this->addElement($regstep_select);
     }
     $this->addElement(new Xoops\Form\Hidden('op', 'save'));
     $this->addElement(new Xoops\Form\Button('', 'submit', XoopsLocale::A_SUBMIT, 'submit'));
 }
예제 #5
0
 /**
  * Returns a {@link Xoops\Form\Element} for editing the value of this field
  *
  * @param XoopsUser $user {@link XoopsUser} object to edit the value of
  * @param ProfileProfile $profile {@link ProfileProfile} object to edit the value of
  *
  * @return Xoops\Form\Element
  **/
 public function getEditElement(XoopsUser $user, ProfileProfile $profile)
 {
     $xoops = Xoops::getInstance();
     $value = in_array($this->getVar('field_name'), $this->getUserVars()) ? $user->getVar($this->getVar('field_name'), 'e') : $profile->getVar($this->getVar('field_name'), 'e');
     $caption = $this->getVar('field_title');
     $caption = defined($caption) ? constant($caption) : $caption;
     $name = $this->getVar('field_name', 'e');
     $options = $this->getVar('field_options');
     if (is_array($options)) {
         //asort($options);
         foreach (array_keys($options) as $key) {
             $optval = defined($options[$key]) ? constant($options[$key]) : $options[$key];
             $optkey = defined($key) ? constant($key) : $key;
             unset($options[$key]);
             $options[$optkey] = $optval;
         }
     }
     switch ($this->getVar('field_type')) {
         default:
         case "autotext":
             //autotext is not for editing
             $element = new Xoops\Form\Label($caption, $this->getOutputValue($user, $profile));
             break;
         case "textbox":
             $element = new Xoops\Form\Text($caption, $name, 35, $this->getVar('field_maxlength'), $value);
             break;
         case "textarea":
             $element = new Xoops\Form\TextArea($caption, $name, $value, 4, 30);
             break;
         case "dhtml":
             $element = new Xoops\Form\DhtmlTextArea($caption, $name, $value, 10, 30);
             break;
         case "select":
             $element = new Xoops\Form\Select($caption, $name, $value);
             // If options do not include an empty element, then add a blank option to prevent any default selection
             if (!in_array('', array_keys($options))) {
                 $element->addOption('', XoopsLocale::NONE);
                 $eltmsg = empty($caption) ? sprintf(XoopsLocale::F_ENTER, $name) : sprintf(XoopsLocale::F_ENTER, $caption);
                 $eltmsg = str_replace('"', '\\"', stripslashes($eltmsg));
                 $element->customValidationCode[] = "\nvar hasSelected = false; var selectBox = myform.{$name};" . "for (i = 0; i < selectBox.options.length; i++  ) { if ( selectBox.options[i].selected == true && selectBox.options[i].value != '' ) { hasSelected = true; break; } }" . "if ( !hasSelected ) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }";
             }
             $element->addOptionArray($options);
             break;
         case "select_multi":
             $element = new Xoops\Form\Select($caption, $name, $value, 5, true);
             $element->addOptionArray($options);
             break;
         case "radio":
             $element = new Xoops\Form\Radio($caption, $name, $value);
             $element->addOptionArray($options);
             break;
         case "checkbox":
             $element = new Xoops\Form\Checkbox($caption, $name, $value);
             $element->addOptionArray($options);
             break;
         case "yesno":
             $element = new Xoops\Form\RadioYesNo($caption, $name, $value);
             break;
         case "group":
             $element = new Xoops\Form\SelectGroup($caption, $name, true, $value);
             break;
         case "group_multi":
             $element = new Xoops\Form\SelectGroup($caption, $name, true, $value, 5, true);
             break;
         case "language":
             $element = new Xoops\Form\SelectLanguage($caption, $name, $value);
             break;
         case "date":
             $element = new Xoops\Form\DateSelect($caption, $name, 15, $value);
             break;
         case "longdate":
             $element = new Xoops\Form\DateSelect($caption, $name, 15, str_replace("-", "/", $value));
             break;
         case "datetime":
             $element = new Xoops\Form\DateTime($caption, $name, 15, $value);
             break;
         case "timezone":
             $element = new Xoops\Form\SelectTimeZone($caption, $name, $value);
             $element->setExtra("style='width: 280px;'");
             break;
         case "rank":
             $ranklist = $xoops->service('userrank')->getAssignableUserRankList()->getValue();
             if ($ranklist !== null) {
                 $element = new Xoops\Form\Select($caption, $name, $value);
                 $element->addOption(0, "--------------");
                 $element->addOptionArray($ranklist);
             } else {
                 $element = new Xoops\Form\Hidden($name, $value);
             }
             break;
         case 'theme':
             $element = new Xoops\Form\Select($caption, $name, $value);
             $element->addOption("0", _PROFILE_MA_SITEDEFAULT);
             $handle = opendir(\XoopsBaseConfig::get('themes-path') . '/');
             $dirlist = array();
             while (false !== ($file = readdir($handle))) {
                 if (is_dir(\XoopsBaseConfig::get('themes-path') . '/' . $file) && !preg_match("/^[.]{1,2}\$/", $file) && strtolower($file) != 'cvs') {
                     if (XoopsLoad::fileExists(\XoopsBaseConfig::get('themes-path') . "/" . $file . "/theme.html") && in_array($file, $xoops->getConfig('theme_set_allowed'))) {
                         $dirlist[$file] = $file;
                     }
                 }
             }
             closedir($handle);
             if (!empty($dirlist)) {
                 asort($dirlist);
                 $element->addOptionArray($dirlist);
             }
             break;
     }
     if ($this->getVar('field_description') != "") {
         $element->setDescription($this->getVar('field_description'));
     }
     return $element;
 }