Exemplo n.º 1
0
 /**
  * Get the options for this PHAT_Element
  *
  * @return string The HTML form for retrieving the options
  * @access public
  */
 function getOptions()
 {
     $className = get_class($this);
     $properName = ucfirst(str_ireplace('phat_', '', $className));
     if (isset($_REQUEST['PHAT_OptionSet']) && $_REQUEST['PHAT_OptionSet'] != 0 && $_REQUEST['PHAT_OptionSet'] != $this->getOptionSet()) {
         $this->setOptionSet($_REQUEST['PHAT_OptionSet']);
         $db = new PHPWS_DB('mod_phatform_options');
         $db->addWhere('id', $this->getOptionSet());
         $optionResult = $db->select();
         $this->_optionText = array();
         $this->_optionValues = array();
         $this->_optionText = unserialize(stripslashes($optionResult[0]['optionSet']));
         $this->_optionValues = unserialize(stripslashes($optionResult[0]['valueSet']));
     }
     if (!empty($_REQUEST['PHAT_ElementNumOptions']) && is_numeric($_REQUEST['PHAT_ElementNumOptions'])) {
         $loops = $_REQUEST['PHAT_ElementNumOptions'];
         /* must reset these arrays for when a new number of options is entered */
         $oldText = $this->_optionText;
         $oldValues = $this->_optionValues;
         $this->_optionText = array();
         $this->_optionValues = array();
         for ($i = 0; $i < $loops; $i++) {
             if (isset($oldText[$i])) {
                 $this->_optionText[$i] = $oldText[$i];
             } else {
                 $this->_optionText[$i] = NULL;
             }
             if (isset($oldValues[$i])) {
                 $this->_optionValues[$i] = $oldValues[$i];
             } else {
                 $this->_optionValues[$i] = NULL;
             }
         }
     } else {
         if (sizeof($this->_optionText) > 0) {
             $loops = sizeof($this->_optionText);
         } else {
             return PHPWS_Error::get(PHATFORM_ZERO_OPTIONS, 'phatform', 'PHAT_Element::getOptions()');
         }
     }
     $elements[0] = '<input type="hidden" name="module" value="phatform" /><input type="hidden" name="PHAT_EL_OP" value="SaveElementOptions" />';
     if (PHAT_SHOW_INSTRUCTIONS) {
         $GLOBALS['CNT_phatform']['title'] = dgettext('phatform', 'Option Instructions');
     }
     $editTags['NUMBER_LABEL'] = dgettext('phatform', 'Option');
     $editTags['INPUT_LABEL'] = dgettext('phatform', 'Text');
     $editTags['VALUE_LABEL'] = dgettext('phatform', 'Value');
     $editTags['DEFAULT_LABEL'] = dgettext('phatform', 'Default');
     $editTags['OPTIONS'] = '';
     $rowClass = NULL;
     for ($i = 0; $i < $loops; $i++) {
         $optionRow['OPTION_NUMBER'] = $i + 1;
         $element = new Form_TextField("PHAT_ElementOptions[{$i}]", $this->_optionText[$i]);
         $element->setSize(PHAT_DEFAULT_SIZE, PHAT_DEFAULT_MAXSIZE);
         $optionRow['OPTION_INPUT'] = $element->get();
         $element = new Form_TextField("PHAT_ElementValues[{$i}]", $this->_optionValues[$i]);
         $element->setSize(PHAT_DEFAULT_SIZE, PHAT_DEFAULT_MAXSIZE);
         $optionRow['VALUE_INPUT'] = $element->get();
         $check = NULL;
         if ($className == 'PHAT_checkbox' || $className == 'PHAT_Multiselect') {
             if (isset($this->_optionValues[$i]) && (isset($this->_value[$i]) && $this->_optionValues[$i] == $this->_value[$i])) {
                 $check = $i;
             }
             $element = new Form_CheckBox("PHAT_ElementDefault[{$i}]", $i);
             $element->setMatch($check);
             $optionRow['OPTION_DEFAULT'] = $element->get();
         } else {
             if (isset($this->_optionValues[$i]) && $this->_optionValues[$i] == $this->_value) {
                 $check = $i;
             }
             $element = new Form_CheckBox('PHAT_ElementDefault', $i);
             $element->setMatch($check);
             $optionRow['OPTION_DEFAULT'] = $element->get();
         }
         $optionRow['ROW_CLASS'] = $rowClass;
         if ($i % 2) {
             $rowClass = ' class="bgcolor1"';
         } else {
             $rowClass = null;
         }
         $editTags['OPTIONS'] .= PHPWS_Template::processTemplate($optionRow, 'phatform', 'element/option.tpl');
     }
     $check = NULL;
     if ($this->getId()) {
         if ($this->_optionText == $this->_optionValues && sizeof($this->_optionText) > 0) {
             $check = 1;
         }
     }
     if (isset($_REQUEST['PHAT_SaveOptionSet'])) {
         $setName = $_REQUEST['PHAT_SaveOptionSet'];
     } else {
         $setName = NULL;
     }
     $element = new Form_Checkbox('PHAT_ElementUseText', 1);
     $element->setMatch($check);
     $editTags['USE_TEXT_CHECK'] = dgettext('phatform', 'Use option text as values') . ': ' . $element->get();
     $editTags['SAVE_OPTION_SET'] = dgettext('phatform', 'Save option set as') . ': ' . PHPWS_Form::formTextField('PHAT_SaveOptionSet', $setName, PHAT_DEFAULT_SIZE, PHAT_DEFAULT_MAXSIZE);
     $editTags['BACK_BUTTON'] = PHPWS_Form::formSubmit(dgettext('phatform', 'Back'), 'PHAT_OptionBack');
     $editTags['SAVE_BUTTON'] = PHPWS_Form::formSubmit(dgettext('phatform', 'Save ' . $properName));
     $elements[0] .= PHPWS_Template::processTemplate($editTags, 'phatform', 'element/optionList.tpl');
     return PHPWS_Form::makeForm('PHAT_Options', 'index.php', $elements, 'post', NULL, NULL);
 }
Exemplo n.º 2
0
 public function get()
 {
     $breaker = null;
     if ($this->use_editor) {
         $text = PHPWS_Text::decodeText($this->value);
         return javascript('ckeditor', array('ID' => $this->id, 'NAME' => $this->name, 'VALUE' => $text));
     }
     $value = preg_replace('/<br\\s?\\/?>(\\r\\n)?/', "\n", $this->value);
     if (ord(substr($value, 0, 1)) == 13) {
         $value = "\n" . $value;
     }
     if (isset($this->width)) {
         $style[] = 'width : ' . $this->width;
     } else {
         $dimensions[] = $this->getCols(true);
     }
     if (isset($this->height)) {
         $style[] = 'height : ' . $this->height;
     } else {
         $dimensions[] = $this->getRows(true);
     }
     if (isset($style)) {
         $dimensions[] = 'style="' . implode('; ', $style) . '"';
     }
     if (!USE_BREAKER && !empty($this->_form->use_breaker)) {
         $check_name = sprintf('%s_breaker', $this->name);
         $checkbox = new Form_Checkbox($check_name);
         $checkbox->_form = $this->_form;
         $checkbox->setLabel(_('Break newlines'));
         $checkbox->setId($check_name);
         $breaker = sprintf('<div class="textarea-breaker">%s %s</div>', $checkbox->get(), $checkbox->getLabel(true, true));
     }
     return $breaker . '<textarea ' . $this->getName(true) . $this->getTitle(true) . $this->getPlaceholder() . $this->getDisabled() . $this->getReadOnly() . implode(' ', $dimensions) . ' ' . $this->getData() . sprintf('>%s</textarea>', $value);
 }