/** * 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->addCustomValidationCode("\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, $value); break; case "longdate": $element = new Xoops\Form\DateSelect($caption, $name, str_replace("-", "/", $value)); break; case "datetime": $element = new Xoops\Form\DateTime($caption, $name, $value); break; case "timezone": $element = new Xoops\Form\SelectTimeZone($caption, $name, $value); 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; }