コード例 #1
0
ファイル: Element.php プロジェクト: HaldunA/phpwebsite
 /**
  * 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);
 }
コード例 #2
0
ファイル: PHPWS_Form.php プロジェクト: HaldunA/phpwebsite
 public static function formCheckBox($name, $value = 1, $match = null, $match_diff = null, $label = null)
 {
     $element = new Form_Checkbox($name, $value);
     $element->setMatch($match);
     return $element->get() . ' ' . $label;
 }