public function __construct($name = null, $attributes = null, $data = null)
 {
     parent::__construct($name, $attributes, null);
     $this->addElement('text', $data . '_c', array('size' => 5));
     $this->addStatic()->setContent(' ');
     $sel = $this->addElement('select', $data . '_t', array('size' => 1), array('options' => array('%' => '%', '$' => Am_Currency::getDefault())));
 }
 public function __construct($name)
 {
     parent::__construct('', array('id' => 'mail-editor'));
     $subject = $this->addElement('text', 'subject', array('size' => 80))->setLabel(___('Subject'));
     $subject->addRule('required');
     $this->addStatic()->setContent('<br /><br />');
     $format = $this->addGroup(null)->setLabel(___('E-Mail Format'));
     $format->addRadio('format', array('value' => 'html'))->setContent(___('HTML Message'));
     $format->addRadio('format', array('value' => 'text'))->setContent(___('Plain-Text Message'));
     $this->addStatic()->setContent('<br /><br />');
     $this->editor = $this->addElement(new Am_Form_Element_HtmlEditor('txt', null, true));
     $this->editor->addRule('required');
     $this->addStatic()->setContent('<br /><br />');
     $this->tagsOptions = Am_Mail_TemplateTypes::getInstance()->getTagsOptions($name);
     $tagsOptions = array();
     foreach ($this->tagsOptions as $k => $v) {
         $tagsOptions[$k] = "{$k} - {$v}";
     }
     $sel = $this->addSelect('', array('id' => 'insert-tags'));
     $sel->loadOptions(array_merge(array('' => ''), $tagsOptions));
     $this->addStatic()->setContent('<br /><br />');
     $this->addClass('no-label');
     $fileChooser = new Am_Form_Element_Upload('attachments', array('multiple' => 1), array('prefix' => EmailTemplate::ATTACHMENT_FILE_PREFIX));
     $this->addElement($fileChooser)->setLabel(___('Attachments'));
 }
 public function __construct($name = null, $attributes = null, $data = null)
 {
     parent::__construct($name, $attributes, $data);
     $require = !$data['dont_require'];
     $years = @$data['years'];
     if (!$years) {
         $years = 10;
     }
     $m = $this->addSelect('m')->loadOptions($this->getMonthOptions());
     if ($require) {
         $m->addRule('required', ___('Invalid Expiration Date - Month'));
     }
     $y = $this->addSelect('y')->loadOptions($this->getYearOptions($years));
     if ($require) {
         $y->addRule('required', ___('Invalid Expiration Date - Year'));
     }
 }
 /**
  * Class constructor
  *
  * Hierselect element can understand the following keys in $data parameter:
  *   - 'options': data to populate child elements' options with. Passed to
  *     {@link loadOptions()} method.
  *   - 'size': number of selects in hierselect. If not given will be set
  *     from size of options array or size of array passed to setValue()
  * $data is propagated to created Select elements with these keys removed.
  *
  * @param string       $name       Element name
  * @param string|array $attributes Attributes (either a string or an array)
  * @param array        $data       Additional element data
  */
 public function __construct($name = null, $attributes = null, array $data = array())
 {
     if (!empty($data['size'])) {
         $this->size = $data['size'];
     }
     $options = isset($data['options']) ? $data['options'] : array();
     unset($data['options'], $data['size']);
     parent::__construct($name, $attributes, $data);
     $this->loadOptions($options);
 }
Exemple #5
0
 /**
  * Class constructor
  *
  * The following keys may appear in $data array:
  * - 'language': date language
  * - 'format': Format of the date, based on PHP's date() function.
  *   The following characters are currently recognised in format string:
  *   <pre>
  *       D => Short names of days
  *       l => Long names of days
  *       d => Day numbers
  *       M => Short names of months
  *       F => Long names of months
  *       m => Month numbers
  *       Y => Four digit year
  *       y => Two digit year
  *       h => 12 hour format
  *       H => 23 hour  format
  *       i => Minutes
  *       s => Seconds
  *       a => am/pm
  *       A => AM/PM
  *   </pre>
  * - 'minYear': Minimum year in year select
  * - 'maxYear': Maximum year in year select
  * - 'addEmptyOption': Should an empty option be added to the top of
  *    each select box?
  * - 'emptyOptionValue': The value passed by the empty option.
  * - 'emptyOptionText': The text displayed for the empty option.
  * - 'optionIncrement': Step to increase the option values by (works for 'i' and 's')
  *
  * @param    string  Element name
  * @param    mixed   Attributes (either a string or an array)
  * @param    array   Element data (label, options and data used for element creation)
  */
 public function __construct($name = null, $attributes = null, $data = null)
 {
     parent::__construct($name, $attributes, $data);
     $locale =& $this->locale[$this->data['language']];
     $backslash = false;
     $separators = array();
     $separator = '';
     for ($i = 0, $length = strlen($this->data['format']); $i < $length; $i++) {
         $sign = $this->data['format'][$i];
         if ($backslash) {
             $backslash = false;
             $separator .= $sign;
         } else {
             $loadSelect = true;
             switch ($sign) {
                 case 'D':
                     // Sunday is 0 like with 'w' in date()
                     $options = $locale['weekdays_short'];
                     break;
                 case 'l':
                     $options = $locale['weekdays_long'];
                     break;
                 case 'd':
                     $options = $this->createOptionList(1, 31);
                     break;
                 case 'M':
                     $options = $locale['months_short'];
                     array_unshift($options, '');
                     unset($options[0]);
                     break;
                 case 'm':
                     $options = $this->createOptionList(1, 12);
                     break;
                 case 'F':
                     $options = $locale['months_long'];
                     array_unshift($options, '');
                     unset($options[0]);
                     break;
                 case 'Y':
                     $options = $this->createOptionList($this->data['minYear'], $this->data['maxYear'], $this->data['minYear'] > $this->data['maxYear'] ? -1 : 1);
                     break;
                 case 'y':
                     $options = $this->createOptionList($this->data['minYear'], $this->data['maxYear'], $this->data['minYear'] > $this->data['maxYear'] ? -1 : 1);
                     array_walk($options, create_function('&$v,$k', '$v = substr($v,-2);'));
                     break;
                 case 'h':
                     $options = $this->createOptionList(1, 12);
                     break;
                 case 'g':
                     $options = $this->createOptionList(1, 12);
                     array_walk($options, create_function('&$v,$k', '$v = intval($v);'));
                     break;
                 case 'H':
                     $options = $this->createOptionList(0, 23);
                     break;
                 case 'i':
                     $options = $this->createOptionList(0, 59, $this->data['optionIncrement']['i']);
                     break;
                 case 's':
                     $options = $this->createOptionList(0, 59, $this->data['optionIncrement']['s']);
                     break;
                 case 'a':
                     $options = array('am' => 'am', 'pm' => 'pm');
                     break;
                 case 'A':
                     $options = array('AM' => 'AM', 'PM' => 'PM');
                     break;
                 case 'W':
                     $options = $this->createOptionList(1, 53);
                     break;
                 case '\\':
                     $backslash = true;
                     $loadSelect = false;
                     break;
                 default:
                     $separator .= ' ' == $sign ? '&nbsp;' : $sign;
                     $loadSelect = false;
             }
             if ($loadSelect) {
                 if (0 < count($this)) {
                     $separators[] = $separator;
                 }
                 $separator = '';
                 // Should we add an empty option to the top of the select?
                 if (!is_array($this->data['addEmptyOption']) && $this->data['addEmptyOption'] || is_array($this->data['addEmptyOption']) && !empty($this->data['addEmptyOption'][$sign])) {
                     // Using '+' array operator to preserve the keys
                     if (is_array($this->data['emptyOptionText']) && !empty($this->data['emptyOptionText'][$sign])) {
                         $options = array($this->data['emptyOptionValue'] => $this->data['emptyOptionText'][$sign]) + $options;
                     } else {
                         $options = array($this->data['emptyOptionValue'] => $this->data['emptyOptionText']) + $options;
                     }
                 }
                 $this->addSelect($sign, array('id' => self::generateId($this->getName() . "[{$sign}]")) + $this->getAttributes())->loadOptions($options);
             }
         }
     }
     $separators[] = $separator . ($backslash ? '\\' : '');
     $this->setSeparator($separators);
 }
Exemple #6
0
    public function __construct($name = null, $attributes = null, $data = null)
    {
        parent::__construct(null, $attributes, $data);
        $this->setSeparator(' ');
        $el = $this->addAdvCheckbox($name);
        $id = $el->getId();
        $this->addScript()->setScript(<<<CUT
// init checkboxed group {$id}
\$(function(){
    var el = \$("#{$id}").closest(".element");
    el.html(el.html().replace(/(<[\\s\\S]+checkbox[\\s\\S]+?>)([\\s\\S]+)/, '\$1<span class="checkboxed-cnt">\$2</span>'));
    \$(".checkboxed-cnt", el).toggle( \$("#{$id}").is(":checked") );
    \$("#{$id}").change(function()
    {
        \$(this).closest(".element").find(".checkboxed-cnt").toggle( this.checked );
    });
});
// end of init checkboxed group    
CUT
);
    }
Exemple #7
0
 /**
  * Class constructor
  *
  * The following keys may appear in $data array:
  * - 'messageProvider': a callback or an instance of a class implementing
  *   HTML_QuickForm2_MessageProvider interface, this will be used to get
  *   localized names of months and weekdays. Some of the default ones will
  *   be used if not given.
  * - 'language': date language, use 'locale' here to display month / weekday
  *   names according to the current locale.
  * - 'format': Format of the date, based on PHP's date() function.
  *   The following characters are currently recognised in format string:
  *   <pre>
  *       D => Short names of days
  *       l => Long names of days
  *       d => Day numbers
  *       M => Short names of months
  *       F => Long names of months
  *       m => Month numbers
  *       Y => Four digit year
  *       y => Two digit year
  *       h => 12 hour format
  *       H => 24 hour format
  *       i => Minutes
  *       s => Seconds
  *       a => am/pm
  *       A => AM/PM
  *   </pre>
  * - 'minYear': Minimum year in year select
  * - 'maxYear': Maximum year in year select
  * - 'addEmptyOption': Should an empty option be added to the top of
  *    each select box?
  * - 'emptyOptionValue': The value passed by the empty option.
  * - 'emptyOptionText': The text displayed for the empty option.
  * - 'optionIncrement': Step to increase the option values by (works for 'i' and 's')
  * - 'minHour': Minimum hour in hour select (only for 24 hour format!)
  * - 'maxHour': Maximum hour in hour select (only for 24 hour format!)
  * - 'minMonth': Minimum month in month select
  * - 'maxMonth': Maximum month in month select
  *
  * @param    string  Element name
  * @param    mixed   Attributes (either a string or an array)
  * @param    array   Element data (label, options and data used for element creation)
  */
 public function __construct($name = null, $attributes = null, array $data = array())
 {
     if (isset($data['messageProvider'])) {
         if (!is_callable($data['messageProvider']) && !$data['messageProvider'] instanceof HTML_QuickForm2_MessageProvider) {
             throw new HTML_QuickForm2_InvalidArgumentException("messageProvider: expecting a callback or an implementation" . " of HTML_QuickForm2_MessageProvider");
         }
         $this->messageProvider = $data['messageProvider'];
     } else {
         if (isset($data['language']) && 'locale' == $data['language']) {
             HTML_QuickForm2_Loader::loadClass('HTML_QuickForm2_MessageProvider_Strftime');
             $this->messageProvider = new HTML_QuickForm2_MessageProvider_Strftime();
         } else {
             HTML_QuickForm2_Loader::loadClass('HTML_QuickForm2_MessageProvider_Default');
             $this->messageProvider = HTML_QuickForm2_MessageProvider_Default::getInstance();
         }
     }
     if (isset($data['language'])) {
         $this->language = $data['language'];
     }
     unset($data['messageProvider'], $data['language']);
     // http://pear.php.net/bugs/bug.php?id=18171
     $this->data['maxYear'] = date('Y');
     parent::__construct($name, $attributes, $data);
     $backslash = false;
     $separators = array();
     $separator = '';
     for ($i = 0, $length = strlen($this->data['format']); $i < $length; $i++) {
         $sign = $this->data['format'][$i];
         if ($backslash) {
             $backslash = false;
             $separator .= $sign;
         } else {
             $loadSelect = true;
             switch ($sign) {
                 case 'D':
                     // Sunday is 0 like with 'w' in date()
                     $options = $this->messageProvider instanceof HTML_QuickForm2_MessageProvider ? $this->messageProvider->get(array('date', 'weekdays_short'), $this->language) : call_user_func($this->messageProvider, array('date', 'weekdays_short'), $this->language);
                     break;
                 case 'l':
                     $options = $this->messageProvider instanceof HTML_QuickForm2_MessageProvider ? $this->messageProvider->get(array('date', 'weekdays_long'), $this->language) : call_user_func($this->messageProvider, array('date', 'weekdays_long'), $this->language);
                     break;
                 case 'd':
                     $options = $this->createOptionList(1, 31);
                     break;
                 case 'M':
                 case 'm':
                 case 'F':
                     $options = $this->createOptionList($this->data['minMonth'], $this->data['maxMonth'], $this->data['minMonth'] > $this->data['maxMonth'] ? -1 : 1);
                     if ('M' == $sign || 'F' == $sign) {
                         $key = 'M' == $sign ? 'months_short' : 'months_long';
                         $names = $this->messageProvider instanceof HTML_QuickForm2_MessageProvider ? $this->messageProvider->get(array('date', $key), $this->language) : call_user_func($this->messageProvider, array('date', $key), $this->language);
                         foreach ($options as $k => &$v) {
                             $v = $names[$k - 1];
                         }
                     }
                     break;
                 case 'Y':
                     $options = $this->createOptionList($this->data['minYear'], $this->data['maxYear'], $this->data['minYear'] > $this->data['maxYear'] ? -1 : 1);
                     break;
                 case 'y':
                     $options = $this->createOptionList($this->data['minYear'], $this->data['maxYear'], $this->data['minYear'] > $this->data['maxYear'] ? -1 : 1);
                     array_walk($options, create_function('&$v,$k', '$v = substr($v,-2);'));
                     break;
                 case 'h':
                     $options = $this->createOptionList(1, 12);
                     break;
                 case 'g':
                     $options = $this->createOptionList(1, 12);
                     array_walk($options, create_function('&$v,$k', '$v = intval($v);'));
                     break;
                 case 'H':
                     $options = $this->createOptionList($this->data['minHour'], $this->data['maxHour'], $this->data['minHour'] > $this->data['maxHour'] ? -1 : 1);
                     break;
                 case 'i':
                     $options = $this->createOptionList(0, 59, $this->data['optionIncrement']['i']);
                     break;
                 case 's':
                     $options = $this->createOptionList(0, 59, $this->data['optionIncrement']['s']);
                     break;
                 case 'a':
                     $options = array('am' => 'am', 'pm' => 'pm');
                     break;
                 case 'A':
                     $options = array('AM' => 'AM', 'PM' => 'PM');
                     break;
                 case 'W':
                     $options = $this->createOptionList(1, 53);
                     break;
                 case '\\':
                     $backslash = true;
                     $loadSelect = false;
                     break;
                 default:
                     $separator .= ' ' == $sign ? '&nbsp;' : $sign;
                     $loadSelect = false;
             }
             if ($loadSelect) {
                 if (0 < count($this)) {
                     $separators[] = $separator;
                 }
                 $separator = '';
                 // Should we add an empty option to the top of the select?
                 if (!is_array($this->data['addEmptyOption']) && $this->data['addEmptyOption'] || is_array($this->data['addEmptyOption']) && !empty($this->data['addEmptyOption'][$sign])) {
                     // Using '+' array operator to preserve the keys
                     if (is_array($this->data['emptyOptionText']) && !empty($this->data['emptyOptionText'][$sign])) {
                         $options = array($this->data['emptyOptionValue'] => $this->data['emptyOptionText'][$sign]) + $options;
                     } else {
                         $options = array($this->data['emptyOptionValue'] => $this->data['emptyOptionText']) + $options;
                     }
                 }
                 $this->addSelect($sign, array('id' => self::generateId($this->getName() . "[{$sign}]")) + $this->getAttributes())->loadOptions($options);
             }
         }
     }
     $separators[] = $separator . ($backslash ? '\\' : '');
     $this->setSeparator($separators);
 }