Пример #1
0
 /**
  * Returns a {@link XoopsFormElement} 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 XoopsFormElement
  **/
 public function getEditElement($user, $profile)
 {
     $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;
         }
     }
     include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
     switch ($this->getVar('field_type')) {
         default:
         case 'autotext':
             //autotext is not for editing
             $element = new XoopsFormLabel($caption, $this->getOutputValue($user, $profile));
             break;
         case 'textbox':
             $element = new XoopsFormText($caption, $name, 35, $this->getVar('field_maxlength'), $value);
             break;
         case 'textarea':
             $element = new XoopsFormTextArea($caption, $name, $value, 4, 30);
             break;
         case 'dhtml':
             $element = new XoopsFormDhtmlTextArea($caption, $name, $value, 10, 30);
             break;
         case 'select':
             $element = new XoopsFormSelect($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))) {
             if (!array_key_exists('', $options)) {
                 $element->addOption('', _NONE);
                 $eltmsg = empty($caption) ? sprintf(_FORM_ENTER, $name) : sprintf(_FORM_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 XoopsFormSelect($caption, $name, $value, 5, true);
             $element->addOptionArray($options);
             break;
         case 'radio':
             $element = new XoopsFormRadio($caption, $name, $value);
             $element->addOptionArray($options);
             break;
         case 'checkbox':
             $element = new XoopsFormCheckBox($caption, $name, $value);
             $element->addOptionArray($options);
             break;
         case 'yesno':
             $element = new XoopsFormRadioYN($caption, $name, $value);
             break;
         case 'group':
             $element = new XoopsFormSelectGroup($caption, $name, true, $value);
             break;
         case 'group_multi':
             $element = new XoopsFormSelectGroup($caption, $name, true, $value, 5, true);
             break;
         case 'language':
             $element = new XoopsFormSelectLang($caption, $name, $value);
             break;
         case 'date':
             $element = new XoopsFormTextDateSelect($caption, $name, 15, $value);
             break;
         case 'longdate':
             $element = new XoopsFormTextDateSelect($caption, $name, 15, str_replace('-', '/', $value));
             break;
         case 'datetime':
             $element = new XoopsFormDatetime($caption, $name, 15, $value);
             break;
         case 'list':
             $element = new XoopsFormSelectList($caption, $name, $value, 1, $options[0]);
             break;
         case 'timezone':
             $element = new XoopsFormSelectTimezone($caption, $name, $value);
             $element->setExtra("style='width: 280px;'");
             break;
         case 'rank':
             $element = new XoopsFormSelect($caption, $name, $value);
             include_once $GLOBALS['xoops']->path('class/xoopslists.php');
             $ranks = XoopsLists::getUserRankList();
             $element->addOption(0, '--------------');
             $element->addOptionArray($ranks);
             break;
         case 'theme':
             $element = new XoopsFormSelectTheme($caption, $name, $value, 1, true);
             break;
     }
     if ($this->getVar('field_description') != '') {
         $element->setDescription($this->getVar('field_description'));
     }
     return $element;
 }
Пример #2
0
 /**
  * Returns a {@link XoopsFormElement} 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 XoopsFormElement
  **/
 function getEditElement($user, $profile)
 {
     $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;
         }
     }
     include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
     switch ($this->getVar('field_type')) {
         default:
         case "autotext":
             //autotext is not for editing
             $element = new XoopsFormLabel($caption, $this->getOutputValue($user, $profile));
             break;
         case "textbox":
             $element = new XoopsFormText($caption, $name, 35, $this->getVar('field_maxlength'), $value);
             break;
         case "textarea":
             $element = new XoopsFormTextArea($caption, $name, $value, 4, 30);
             break;
         case "dhtml":
             $element = new XoopsFormDhtmlTextArea($caption, $name, $value, 10, 30);
             break;
         case "select":
             $element = new XoopsFormSelect($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('', _NONE);
                 $eltmsg = empty($caption) ? sprintf(_FORM_ENTER, $name) : sprintf(_FORM_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 XoopsFormSelect($caption, $name, $value, 5, true);
             $element->addOptionArray($options);
             break;
         case "radio":
             $element = new XoopsFormRadio($caption, $name, $value);
             $element->addOptionArray($options);
             break;
         case "checkbox":
             $element = new XoopsFormCheckBox($caption, $name, $value);
             $element->addOptionArray($options);
             break;
         case "yesno":
             $element = new XoopsFormRadioYN($caption, $name, $value);
             break;
         case "group":
             $element = new XoopsFormSelectGroup($caption, $name, true, $value);
             break;
         case "group_multi":
             $element = new XoopsFormSelectGroup($caption, $name, true, $value, 5, true);
             break;
         case "language":
             $element = new XoopsFormSelectLang($caption, $name, $value);
             break;
         case "date":
             $element = new XoopsFormTextDateSelect($caption, $name, 15, $value);
             break;
         case "longdate":
             $element = new XoopsFormTextDateSelect($caption, $name, 15, str_replace("-", "/", $value));
             break;
         case "datetime":
             $element = new XoopsFormDatetime($caption, $name, 15, $value);
             break;
         case "list":
             $element = new XoopsFormSelectList($caption, $name, $value, 1, $options[0]);
             break;
         case "timezone":
             $element = new XoopsFormSelectTimezone($caption, $name, $value);
             $element->setExtra("style='width: 280px;'");
             break;
         case "rank":
             $element = new XoopsFormSelect($caption, $name, $value);
             include_once $GLOBALS['xoops']->path('class/xoopslists.php');
             $ranks = XoopsLists::getUserRankList();
             $element->addOption(0, "--------------");
             $element->addOptionArray($ranks);
             break;
         case 'theme':
             $element = new XoopsFormSelect($caption, $name, $value);
             $element->addOption("0", _PROFILE_MA_SITEDEFAULT);
             $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') {
                     if (file_exists(XOOPS_THEME_PATH . "/" . $file . "/theme.html") && in_array($file, $GLOBALS['xoopsConfig']['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;
 }
Пример #3
0
 /**
  * Returns a value for output of this field
  *
  * @param XoopsUser $user {@link XoopsUser} object to get the value of
  * @param profileProfile $profile object to get the value of
  *
  * @return string
  **/
 public function getOutputValue(XoopsUser $user, ProfileProfile $profile)
 {
     $xoops = Xoops::getInstance();
     $xoops->loadLanguage('modinfo', 'profile');
     $value = in_array($this->getVar('field_name'), $this->getUserVars()) ? $user->getVar($this->getVar('field_name')) : $profile->getVar($this->getVar('field_name'));
     switch ($this->getVar('field_type')) {
         default:
         case "textbox":
             if ($this->getVar('field_name') == 'url' && $value != '') {
                 return '<a href="' . $xoops->formatURL($value) . '" rel="external">' . $value . '</a>';
             } else {
                 return $value;
             }
             break;
         case "textarea":
         case "dhtml":
         case 'theme':
         case "language":
         case "list":
             return $value;
             break;
         case "select":
         case "radio":
             $options = $this->getVar('field_options');
             if (isset($options[$value])) {
                 $value = htmlspecialchars(defined($options[$value]) ? constant($options[$value]) : $options[$value]);
             } else {
                 $value = "";
             }
             return $value;
             break;
         case "select_multi":
         case "checkbox":
             $options = $this->getVar('field_options');
             $ret = array();
             if (count($options) > 0) {
                 foreach (array_keys($options) as $key) {
                     if (in_array($key, $value)) {
                         $ret[$key] = htmlspecialchars(defined($options[$key]) ? constant($options[$key]) : $options[$key]);
                     }
                 }
             }
             return $ret;
             break;
         case "group":
             $member_handler = $xoops->getHandlerMember();
             $options = $member_handler->getGroupList();
             $ret = isset($options[$value]) ? $options[$value] : '';
             return $ret;
             break;
         case "group_multi":
             $member_handler = $xoops->getHandlerMember();
             $options = $member_handler->getGroupList();
             $ret = array();
             foreach (array_keys($options) as $key) {
                 if (in_array($key, $value)) {
                     $ret[$key] = htmlspecialchars($options[$key]);
                 }
             }
             return $ret;
             break;
         case "longdate":
             //return YYYY/MM/DD format - not optimal as it is not using local date format, but how do we do that
             //when we cannot convert it to a UNIX timestamp?
             return str_replace("-", "/", $value);
         case "date":
             return XoopsLocale::formatTimestamp($value, 's');
             break;
         case "datetime":
             if (!empty($value)) {
                 return XoopsLocale::formatTimestamp($value, 'm');
             } else {
                 return _PROFILE_MI_NEVER_LOGGED_IN;
             }
             break;
         case "autotext":
             $value = $user->getVar($this->getVar('field_name'), 'n');
             //autotext can have HTML in it
             $value = str_replace("{X_UID}", $user->getVar("uid"), $value);
             $value = str_replace("{X_URL}", \XoopsBaseConfig::get('url'), $value);
             $value = str_replace("{X_UNAME}", $user->getVar("uname"), $value);
             return $value;
             break;
         case "rank":
             $userrank = $user->rank();
             $user_rankimage = "";
             if (isset($userrank['image']) && $userrank['image'] != "") {
                 $user_rankimage = '<img src="' . $userrank['image'] . '" alt="' . $userrank['title'] . '" /><br />';
             }
             return $user_rankimage . $userrank['title'];
             break;
         case "yesno":
             return $value ? XoopsLocale::YES : XoopsLocale::NO;
             break;
         case "timezone":
             $timezones = XoopsLists::getTimeZoneList();
             $value = empty($value) ? "0" : (string) $value;
             return $timezones[str_replace('.0', '', $value)];
             break;
     }
 }