";
$thpath = isset($sc_parameters['nothumb']) || vartrue($hide) ? $default : $default_thumb;
$label = "
";
}
else // Images
{
$title = (vartrue($sc_parameters['help'])) ? "title='".$sc_parameters['help']."'" : "";
$width = vartrue($sc_parameters['w'], 120);
$height = vartrue($sc_parameters['h'], 100);
$ret = "
";
// $ret .= $this->text($name,$default); // to be hidden eventually.
return $ret;
// ----------------
}
function filepicker($name, $default, $label = '', $sc_parameters = '')
{
$tp = e107::getParser();
$name_id = $this->name2id($name);
if(is_string($sc_parameters))
{
if(strpos($sc_parameters, '=') === false) $sc_parameters = 'media='.$sc_parameters;
parse_str($sc_parameters, $sc_parameters);
}
$cat = vartrue($sc_parameters['media']) ? $tp->toDB($sc_parameters['media']) : "_common_file";
$default_label = ($default) ? $default : "Choose a file";
$label = "
";
$sc_parameters['mode'] = 'main';
$sc_parameters['action'] = 'dialog';
// $ret .= $this->mediaUrl($cat, $label,$name_id,"mode=dialog&action=list");
$ret .= $this->mediaUrl($cat, $label,$name_id,$sc_parameters);
$ret .= "
";
return $ret;
}
/**
* Date field with popup calendar // NEW in 0.8/2.0
*
* @param string $name the name of the field
* @param integer $datestamp UNIX timestamp - default value of the field
* @param array or str
* @example $frm->datepicker('my_field',time(),'type=date');
* @example $frm->datepicker('my_field',time(),'type=datetime&inline=1');
* @example $frm->datepicker('my_field',time(),'type=date&format=yyyy-mm-dd');
* @example $frm->datepicker('my_field',time(),'type=datetime&format=MM, dd, yyyy hh:ii');
*
* @url http://trentrichardson.com/examples/timepicker/
*/
function datepicker($name, $datestamp = false, $options = null)
{
if(vartrue($options) && is_string($options))
{
parse_str($options,$options);
}
$type = varset($options['type']) ? trim($options['type']) : "date"; // OR 'datetime'
$dateFormat = varset($options['format']) ? trim($options['format']) :e107::getPref('inputdate', '%Y-%m-%d');
$ampm = (preg_match("/%l|%I|%p|%P/",$dateFormat)) ? 'true' : 'false';
if($type == 'datetime' && !varset($options['format']))
{
$dateFormat .= " ".e107::getPref('inputtime', '%H:%M:%S');
}
$dformat = e107::getDate()->toMask($dateFormat);
$id = $this->name2id($name);
$classes = array('date' => 'e-date', 'datetime' => 'e-datetime');
if ($datestamp)
{
$value = is_numeric($datestamp) ? e107::getDate()->convert_date($datestamp, $dateFormat) : $datestamp; //date("d/m/Y H:i:s", $datestamp);
}
$text = "";
// $text .= 'dformat='.$dformat.' defdisp='.$dateFormat;
$class = (isset($classes[$type])) ? $classes[$type] : "tbox e-date";
$size = vartrue($options['size']) ? intval($options['size']) : 40;
$required = vartrue($options['required']) ? "required" : "";
$firstDay = vartrue($options['firstDay']) ? $options['firstDay'] : 0;
$xsize = (vartrue($options['size']) && !is_numeric($options['size'])) ? $options['size'] : 'xlarge';
if(vartrue($options['inline']))
{
$text .= "
";
}
// $text .= "ValueFormat: ".$dateFormat." Value: ".$value;
// $text .= " ({$dformat}) type:".$dateFormat." ".$value;
return $text;
}
/**
* User auto-complete search
*
* @param string $name_fld field name for user name
* @param string $id_fld field name for user id
* @param string $default_name default user name value
* @param integer $default_id default user id
* @param array|string $options [optional] 'readonly' (make field read only), 'name' (db field name, default user_name)
* @return string HTML text for display
*/
function userpicker($name_fld, $id_fld, $default_name, $default_id, $options = array())
{
$tp = e107::getParser();
if(!is_array($options)) parse_str($options, $options);
$default_name = vartrue($default_name, '');
$default_id = vartrue($default_id, 0);
//TODO Auto-calculate $name_fld from $id_fld ie. append "_usersearch" here ?
$fldid = $this->name2id($name_fld);
$hidden_fldid = $this->name2id($id_fld);
$ret = '
";
e107::js('footer-inline', "
\$('#{$fldid}').blur(function () {
\$('#{$fldid}-id').html(\$('#{$hidden_fldid}').val());
});
\$('#{$fldid}-reset').click(function () {
\$('#{$fldid}-id').html('0');
\$('#{$hidden_fldid}').val(0);
\$('#{$fldid}').val('');
return false;
});
");
return $ret;
/*
$label_fld = str_replace('_', '-', $name_fld).'-upicker-lable';
//'.$this->text($id_fld, $default_id, 10, array('id' => false, 'readonly'=>true, 'class'=>'tbox number')).'
$ret = '
';
e107::getJs()->requireCoreLib('scriptaculous/controls.js', 2);
e107::getJs()->footerInline("
//autocomplete fields
\$\$('input[name={$name_fld}]').each(function(el) {
if(el.readOnly) {
el.observe('click', function(ev) { ev.stop(); var el1 = ev.findElement('input'); el1.blur(); } );
el.next('span.indicator').hide();
el.next('div.e-autocomplete').hide();
return;
}
new Ajax.Autocompleter(el, el.next('div.e-autocomplete'), '".e_JS."e_ajax.php', {
paramName: '{$name_fld}',
minChars: 2,
frequency: 0.5,
afterUpdateElement: function(txt, li) {
if(!\$(li)) return;
var elnext = el.next('input[name={$id_fld}]'),
ellab = \$('{$label_fld}');
if(\$(li).id) {
elnext.value = parseInt(\$(li).id);
} else {
elnext.value = 0
}
if(ellab)
{
ellab.removeClassName('warning').removeClassName('success');
ellab.addClassName((elnext.value ? 'success' : 'warning')).update('Id #' + elnext.value);
}
},
indicator: el.next('span.indicator'),
parameters: 'ajax_used=1&ajax_sc=usersearch=".rawurlencode('searchfld='.str_replace('user_', '', vartrue($options['name'], 'user_name')).'--srcfld='.$name_fld)."'
});
});
");
return $ret;
*/
}
/**
* A Rating element
* @var $text
*/
function rate($table,$id,$options=null)
{
$table = preg_replace('/\W/', '', $table);
$id = intval($id);
return e107::getRate()->render($table, $id, $options);
}
function like($table,$id,$options=null)
{
$table = preg_replace('/\W/', '', $table);
$id = intval($id);
return e107::getRate()->renderLike($table,$id,$options);
}
function file($name, $options = array())
{
$options = $this->format_options('file', $name, $options);
//never allow id in format name-value for text fields
return "
get_attributes($options, $name)." />";
}
function upload($name, $options = array())
{
return 'Ready to use upload form fields, optional - file list view';
}
function password($name, $value = '', $maxlength = 50, $options = array())
{
if(is_string($options)) parse_str($options, $options);
$addon = "";
$gen = "";
if(vartrue($options['generate']))
{
$gen = '
";
}
$options['pattern'] = vartrue($options['pattern'],'[\S]{4,}');
$options['required'] = varset($options['required'], 1);
$options['class'] = vartrue($options['class'],'e-password');
if(deftrue('BOOTSTRAP') == 3)
{
$options['class'] .= ' form-control';
}
$options = $this->format_options('text', $name, $options);
//never allow id in format name-value for text fields
$text = "
get_attributes($options, $name)." />";
return "
".$text.$gen." ".vartrue($addon);
}
/**
* Render a bootStrap ProgressBar.
* @param string $name
* @param number $value
* @param array $options
*/
public function progressBar($name,$value,$options=array())
{
if(!deftrue('BOOTSTRAP'))
{
return;
}
$class = vartrue($options['class'],'');
return "
";
}
/**
* Textarea Element
* @param $name
* @param $value
* @param $rows
* @param $cols
* @param $options
* @param $count
*/
function textarea($name, $value, $rows = 10, $cols = 80, $options = array(), $counter = false)
{
if(is_string($options)) parse_str($options, $options);
// auto-height support
if(vartrue($options['size']) && !is_numeric($options['size']))
{
$options['class'] .= " input-".$options['size'];
unset($options['size']); // don't include in html 'size='.
}
elseif(!vartrue($options['noresize']))
{
$options['class'] = (isset($options['class']) && $options['class']) ? $options['class'].' e-autoheight' : 'tbox span7 e-autoheight';
}
$options = $this->format_options('textarea', $name, $options);
//never allow id in format name-value for text fields
return "
".(false !== $counter ? $this->hidden('__'.$name.'autoheight_opt', $counter) : '');
}
/**
* Bbcode Area. Name, value, template, media-Cat, size, options array eg. counter
* IMPORTANT: $$mediaCat is also used is the media-manager category identifier
*/
function bbarea($name, $value, $template = '', $mediaCat='_common', $size = 'large', $options = array())
{
if(is_string($options)) parse_str($options, $options);
//size - large|medium|small
//width should be explicit set by current admin theme
$size = 'input-large';
switch($size)
{
case 'small':
$rows = '7';
$height = "style='height:250px'"; // inline required for wysiwyg
break;
case 'medium':
$rows = '10';
$height = "style='height:375px'"; // inline required for wysiwyg
$size = "input-block-level";
break;
case 'large':
default:
$rows = '15';
$size = 'large input-block-level';
// $height = "style='height:500px;width:1025px'"; // inline required for wysiwyg
break;
}
// auto-height support
$options['class'] = 'tbox bbarea '.($size ? ' '.$size : '').' e-wysiwyg e-autoheight';
$bbbar = '';
$help_tagid = $this->name2id($name)."--preview";
$options['other'] = "onselect='storeCaret(this);' onclick='storeCaret(this);' onkeyup='storeCaret(this);' {$height}";
$counter = vartrue($options['counter'],false);
$ret = "
\n";
$ret .= e107::getBB()->renderButtons($template,$help_tagid);
$ret .= $this->textarea($name, $value, $rows, 70, $options, $counter); // higher thank 70 will break some layouts.
$ret .= "
\n";
$_SESSION['media_category'] = $mediaCat; // used by TinyMce.
return $ret;
// Quick fix - hide TinyMCE links if not installed, dups are handled by JS handler
/*
e107::getJs()->footerInline("
if(typeof tinyMCE === 'undefined')
{
\$$('a.e-wysiwyg-switch').invoke('hide');
}
");
*/
}
/**
* Render a checkbox
* @param string $name
* @param mixed $value
* @param boolean $checked
* @param mixed $options query-string or array or string for a label. eg. label=Hello&foo=bar or array('label'=>Hello') or 'Hello'
* @return void
*/
function checkbox($name, $value, $checked = false, $options = array())
{
if(!is_array($options))
{
if(strpos($options,"=")!==false)
{
parse_str($options, $options);
}
else // Assume it's a label.
{
$options = array('label'=>$options);
}
}
$options = $this->format_options('checkbox', $name, $options);
$options['checked'] = $checked; //comes as separate argument just for convenience
$text = "";
$pre = (vartrue($options['label'])) ? "
" : ""; // Bootstrap compatible markup
$post = (vartrue($options['label'])) ? $options['label']." " : "";
unset($options['label']); // not to be used as attribute;
$text .= "
get_attributes($options, $name, $value)." />";
return $pre.$text.$post;
}
function checkbox_label($label_title, $name, $value, $checked = false, $options = array())
{
return $this->checkbox($name, $value, $checked, $options).$this->label($label_title, $name, $value);
}
function checkbox_switch($name, $value, $checked = false, $label = '')
{
return $this->checkbox($name, $value, $checked).$this->label($label ? $label : LAN_ENABLED, $name, $value);
}
function checkbox_toggle($name, $selector = 'multitoggle', $id = false, $label='')
{
$selector = 'jstarget:'.$selector;
if($id) $id = $this->name2id($id);
return $this->checkbox($name, $selector, false, array('id' => $id,'class' => 'checkbox toggle-all','label'=>$label));
}
function uc_checkbox($name, $current_value, $uc_options, $field_options = array())
{
if(!is_array($field_options)) parse_str($field_options, $field_options);
return '
'.$this->_uc->vetted_tree($name, array($this, '_uc_checkbox_cb'), $current_value, $uc_options, $field_options).'
';
}
/**
* Callback function used with $this->uc_checkbox
*
* @see user_class->select() for parameters
*/
function _uc_checkbox_cb($treename, $classnum, $current_value, $nest_level, $field_options)
{
if($classnum == e_UC_BLANK)
return '';
if (!is_array($current_value))
{
$tmp = explode(',', $current_value);
}
$classIndex = abs($classnum); // Handle negative class values
$classSign = (substr($classnum, 0, 1) == '-') ? '-' : '';
$class = $style = '';
if($nest_level == 0)
{
$class = " strong";
}
else
{
$style = " style='text-indent:" . (1.2 * $nest_level) . "em'";
}
$descr = varset($field_options['description']) ? '
('.$this->_uc->uc_get_classdescription($classnum).') ' : '';
return "
".$this->checkbox($treename.'[]', $classnum, in_array($classnum, $tmp), $field_options).$this->label($this->_uc->uc_get_classname($classIndex).$descr, $treename.'[]', $classnum)."
\n";
}
function uc_label($classnum)
{
return $this->_uc->uc_get_classname($classnum);
}
/**
* A Radio Button Form Element
* @param $name
* @param @value array pair-values|string - auto-detected.
* @param $checked boolean
* @param $options
*/
function radio($name, $value, $checked = false, $options = null)
{
if(!is_array($options)) parse_str($options, $options);
if(is_array($value))
{
return $this->radio_multi($name, $value, $checked, $options);
}
$labelFound = vartrue($options['label']);
unset($options['label']); // label attribute not valid in html5
$options = $this->format_options('radio', $name, $options);
$options['checked'] = $checked; //comes as separate argument just for convenience
// $options['class'] = 'inline';
$text = "";
// return print_a($options,true);
if($labelFound) // Bootstrap compatible markup
{
$text .= "
";
}
$text .= " get_attributes($options, $name, $value)." />";
if(vartrue($options['help']))
{
$text .= "".$options['help']."
";
}
if($labelFound)
{
$text .= $labelFound." ";
}
return $text;
}
/**
* @param name
* @param check_enabled
* @param label_enabled
* @param label_disabled
* @param options
*/
function radio_switch($name, $checked_enabled = false, $label_enabled = '', $label_disabled = '',$options=array())
{
if(!is_array($options)) parse_str($options, $options);
$options_on = varset($options['enabled'],array());
$options_off = varset($options['disabled'],array());
if(vartrue($options['class']) == 'e-expandit' || vartrue($options['expandit'])) // See admin->prefs 'Single Login' for an example.
{
$options_on = array_merge($options, array('class' => 'e-expandit-on'));
$options_off = array_merge($options, array('class' => 'e-expandit-off'));
}
$options_on['label'] = $label_enabled ? defset($label_enabled,$label_enabled) : LAN_ENABLED;
$options_off['label'] = $label_disabled ? defset($label_disabled,$label_disabled) : LAN_DISABLED;
if(vartrue($options['reverse'])) // reverse order.
{
unset($options['reverse']);
return $this->radio($name, 0, !$checked_enabled, $options_off)." ".
$this->radio($name, 1, $checked_enabled, $options_on);
// return $this->radio($name, 0, !$checked_enabled, $options_off)."".$this->label($label_disabled ? $label_disabled : LAN_DISABLED, $name, 0)." ".
// $this->radio($name, 1, $checked_enabled, $options_on)."".$this->label($label_enabled ? $label_enabled : LAN_ENABLED, $name, 1);
}
// $helpLabel = (is_array($help)) ? vartrue($help[$value]) : $help;
// Bootstrap Style Code - for use later.
// ['help'] = $helpLabel;
// $text[] = $this->radio($name, $value, (string) $checked === (string) $value, $options);
return $this->radio($name, 1, $checked_enabled, $options_on)." ".$this->radio($name, 0, !$checked_enabled, $options_off);
// return $this->radio($name, 1, $checked_enabled, $options_on)."".$this->label($label_enabled ? $label_enabled : LAN_ENABLED, $name, 1)."
// ".$this->radio($name, 0, !$checked_enabled, $options_off)."".$this->label($label_disabled ? $label_disabled : LAN_DISABLED, $name, 0);
}
/**
* XXX INTERNAL ONLY - Use radio() instead. array will automatically trigger this internal method.
* @param string $name
* @param array $elements = arrays value => label
* @param string/integer $checked = current value
* @param boolean $multi_line
* @param mixed $help array of field help items or string of field-help (to show on all)
*/
private function radio_multi($name, $elements, $checked, $options=array(), $help = null)
{
/* // Bootstrap Test.
return'
Option one is this and that—be sure to include why its great
Option one is this and that—be sure to include why its great
Option two can be something else and selecting it will deselect option one
';
*/
$text = array();
if(is_string($elements)) parse_str($elements, $elements);
if(!is_array($options)) parse_str($options, $options);
$help = '';
if(vartrue($options['help']))
{
$help = "
".$options['help']."
";
unset($options['help']);
}
foreach ($elements as $value => $label)
{
$label = defset($label, $label);
$helpLabel = (is_array($help)) ? vartrue($help[$value]) : $help;
// Bootstrap Style Code - for use later.
$options['label'] = $label;
$options['help'] = $helpLabel;
$text[] = $this->radio($name, $value, (string) $checked === (string) $value, $options);
// $text[] = $this->radio($name, $value, (string) $checked === (string) $value)."".$this->label($label, $name, $value).(isset($helpLabel) ? "
".$helpLabel."
" : '');
}
if($multi_line === false)
{
// return implode(" ", $text);
}
// support of UI owned 'newline' parameter
if(!varset($options['sep']) && vartrue($options['newline'])) $options['sep'] = '
'; // TODO div class=separator?
$separator = varset($options['sep']," ");
// return print_a($text,true);
return implode($separator, $text).$help;
// return implode("\n", $text);
//XXX Limiting markup.
// return "
".implode("
", $text)."
";
}
/**
* Just for BC - use the $options['label'] instead.
*/
function label($text, $name = '', $value = '')
{
e107::getMessage()->addDebug("Deprecated \$frm->label() used");
$for_id = $this->_format_id('', $name, $value, 'for');
return "
{$text} ";
}
function help($text)
{
return !empty($text) ? '
'.$text.'
' : '';
}
function select_open($name, $options = array())
{
$options = $this->format_options('select', $name, $options);
return "
get_attributes($options, $name).">";
}
/**
* @DEPRECATED - use select() instead.
*/
function selectbox($name, $option_array, $selected = false, $options = array(), $defaultBlank= false)
{
return $this->select($name, $option_array, $selected, $options, $defaultBlank);
}
/**
*
* @param string $name
* @param array $option_array
* @param boolean $selected [optional]
* @param string|array $options [optional]
* @param boolean|string $defaultBlank [optional] set to TRUE if the first entry should be blank, or to a string to use it for the blank description.
* @return string HTML text for display
*/
function select($name, $option_array, $selected = false, $options = array(), $defaultBlank= false)
{
if(!is_array($options)) parse_str($options, $options);
if($option_array === 'yesno')
{
$option_array = array(1 => LAN_YES, 0 => LAN_NO);
}
if(vartrue($options['multiple']))
{
$name = (strpos($name, '[') === false) ? $name.'[]' : $name;
if(!is_array($selected)) $selected = explode(",",$selected);
}
$text = $this->select_open($name, $options)."\n";
if(isset($options['default']))
{
$text .= $this->option($options['default'], varset($options['defaultValue']));
}
elseif($defaultBlank)
{
$diz = is_string($defaultBlank) ? $defaultBlank : ' ';
$text .= $this->option($diz, '');
}
if(varset($options['useValues'])) // use values as keys.
{
$new = array();
foreach($option_array as $v)
{
$new[$v] = $v;
}
$option_array = $new;
}
$text .= $this->option_multi($option_array, $selected)."\n".$this->select_close();
return $text;
}
//TODO
/**
* Universal Userclass selector - checkboxes, dropdown, everything.
* @param $name - form element name
* @param $curval - current userclass value(s) as array or comma separated.
* @param $type - 'checkbox', 'dropdown',
* @param options - query string or array. 'options=admin,mainadmin,classes&vetted=1&exclusions=0' etc.
* @return the userclass form element
*/
function userclass($name, $curval, $type, $options)
{
}
/**
* Renders a generic search box. If $filter has values, a filter box will be included with the options provided.
*
*/
function search($name, $searchVal, $submitName, $filterName='', $filterArray=false, $filterVal=false)
{
$tp = e107::getParser();
$text = ''.$tp->toGlyph('fa-search').'
'.$this->text($name, $searchVal,20,'class=search-query').'
'.LAN_GO.'
';
if(is_array($filter))
{
$text .= $this->selectbox($$filterName, $filterArray, $filterVal);
}
// $text .= $this->admin_button($submitName,LAN_SEARCH,'search');
return $text;
/*
$text .=
Display All
Clear Filter
General
Misc
Test 3
Display All
Filter
*/
}
function uc_select($name, $current_value, $uc_options, $select_options = array(), $opt_options = array())
{
return $this->select_open($name, $select_options)."\n".$this->_uc->vetted_tree($name, array($this, '_uc_select_cb'), $current_value, $uc_options, $opt_options)."\n".$this->select_close();
}
// Callback for vetted_tree - Creates the option list for a selection box
function _uc_select_cb($treename, $classnum, $current_value, $nest_level)
{
$classIndex = abs($classnum); // Handle negative class values
$classSign = (substr($classnum, 0, 1) == '-') ? '-' : '';
if($classnum == e_UC_BLANK)
return $this->option(' ', '');
$tmp = explode(',', $current_value);
if($nest_level == 0)
{
$prefix = '';
$style = "font-weight:bold; font-style: italic;";
}
elseif($nest_level == 1)
{
$prefix = ' ';
$style = "font-weight:bold";
}
else
{
$prefix = ' '.str_repeat('--', $nest_level - 1).'>';
$style = '';
}
return $this->option($prefix.$this->_uc->uc_get_classname($classnum), $classSign.$classIndex, ($current_value !== '' && in_array($classnum, $tmp)), array("style"=>"{$style}"))."\n";
}
function optgroup_open($label, $disabled = false, $options = null)
{
return "";
}
/**
* tag generation.
* @param $option_title
* @param $value
* @param $selected
* @param $options (eg. disabled=1)
*/
function option($option_title, $value, $selected = false, $options = '')
{
if(is_string($options)) parse_str($options, $options);
if(false === $value) $value = '';
$options = $this->format_options('option', '', $options);
$options['selected'] = $selected; //comes as separate argument just for convenience
return " get_attributes($options).">".defset($option_title, $option_title)." ";
}
/**
* Use selectbox() instead.
*/
function option_multi($option_array, $selected = false, $options = array())
{
if(is_string($option_array)) parse_str($option_array, $option_array);
$text = '';
foreach ($option_array as $value => $label)
{
if(is_array($label))
{
$text .= $this->optgroup_open($value);
foreach($label as $val => $lab)
{
if(is_array($lab))
{
$text .= $this->optgroup_open($val,null,array('class'=>'level-2')); // Not valid HTML5 - but appears to work in modern browsers.
foreach($lab as $k=>$v)
{
$text .= $this->option($v, $k, (is_array($selected) ? in_array($k, $selected) : $selected == $k), $options)."\n";
}
$text .= $this->optgroup_close($val);
}
else
{
$text .= $this->option($lab, $val, (is_array($selected) ? in_array($val, $selected) : $selected == $val), $options)."\n";
}
}
$text .= $this->optgroup_close();
}
else
{
$text .= $this->option($label, $value, (is_array($selected) ? in_array($value, $selected) : $selected == $value), $options)."\n";
}
}
return $text;
}
function optgroup_close()
{
return " ";
}
function select_close()
{
return " ";
}
function hidden($name, $value, $options = array())
{
$options = $this->format_options('hidden', $name, $options);
return "
get_attributes($options, $name, $value)." />";
}
/**
* Generate hidden security field
* @return string
*/
function token()
{
return "
";
}
function submit($name, $value, $options = array())
{
$options = $this->format_options('submit', $name, $options);
return "
get_attributes($options, $name, $value)." />";
}
function submit_image($name, $value, $image, $title='', $options = array())
{
$tp = e107::getParser();
$options = $this->format_options('submit_image', $name, $options);
switch ($image)
{
case 'edit':
$icon = "e-edit-32";
$options['class'] = $options['class'] == 'action' ? 'btn btn-default action edit' : $options['class'];
break;
case 'delete':
$icon = "e-delete-32";
$options['class'] = $options['class'] == 'action' ? 'btn btn-default action delete' : $options['class'];
$options['other'] = 'data-confirm="'.LAN_JSCONFIRM.'"';
break;
case 'execute':
$icon = "e-execute-32";
$options['class'] = $options['class'] == 'action' ? 'btn btn-default action execute' : $options['class'];
break;
case 'view':
$icon = "e-view-32";
$options['class'] = $options['class'] == 'action' ? 'btn btn-default action view' : $options['class'];
break;
}
$options['title'] = $title;//shorthand
return "
get_attributes($options, $name, $value)." >".$tp->toIcon($icon)." ";
}
/**
* Alias of admin_button, adds the etrigger_ prefix required for UI triggers
* @see e_form::admin_button()
*/
function admin_trigger($name, $value, $action = 'submit', $label = '', $options = array())
{
return $this->admin_button('etrigger_'.$name, $value, $action, $label, $options);
}
/**
* Generic Button Element.
* @param string $name
* @param string $value
* @param string $action [optional] default is submit - use 'dropdown' for a bootstrap dropdown button.
* @param string $label [optional]
* @param string|array $options [optional]
* @return string
*/
public function button($name, $value, $action = 'submit', $label = '', $options = array())
{
if(deftrue('BOOTSTRAP') && $action == 'dropdown' && is_array($value))
{
// $options = $this->format_options('admin_button', $name, $options);
$options['class'] = vartrue($options['class']);
$align = vartrue($options['align'],'left');
$text = '
';
return $text;
}
return $this->admin_button($name, $value, $action, $label, $options);
}
/**
* Render a Breadcrumb in Bootstrap format.
* @param $array
*/
function breadcrumb($array)
{
if(!is_array($array)){ return; }
$opt = array();
$homeIcon = e107::getParser()->toGlyph('icon-home.glyph',false);
$opt[] = "
".$homeIcon." "; // Add Site-Pref to disable?
$text = '
";
// return print_a($opt,true);
return $text;
}
/**
* Admin Button - for front-end, use button();
* @param string $name
* @param string $value
* @param string $action [optional] default is submit
* @param string $label [optional]
* @param string|array $options [optional]
* @return string
*/
function admin_button($name, $value, $action = 'submit', $label = '', $options = array())
{
$btype = 'submit';
if(strpos($action, 'action') === 0) $btype = 'button';
$options = $this->format_options('admin_button', $name, $options);
$options['class'] = vartrue($options['class']);
$options['class'] .= ' btn '.$action.' ';//shorthand
if(empty($label)) $label = $value;
switch ($action)
{
case 'update':
case 'create':
case 'import':
case 'submit':
$options['class'] .= 'btn-success';
break;
case 'checkall':
$options['class'] .= 'btn-mini';
break;
case 'cancel':
// use this for neutral colors.
break;
case 'delete':
$options['class'] .= 'btn-danger';
$options['other'] = 'data-confirm="'.LAN_JSCONFIRM.'"';
break;
case 'execute':
$options['class'] .= 'btn-success';
break;
case 'other':
case 'login':
$options['class'] .= 'btn-primary';
break;
case 'warning':
case 'confirm':
$options['class'] .= 'btn-warning';
break;
case 'batch':
case 'batch e-hide-if-js': // FIXME hide-js shouldn't be here.
$options['class'] .= 'btn-primary';
break;
case 'filter':
case 'filter e-hide-if-js': // FIXME hide-js shouldn't be here.
$options['class'] .= 'btn-primary';
break;
default:
$options['class'] .= 'btn-default';
break;
}
return "
get_attributes($options, $name).">{$label}
";
}
function getNext()
{
if(!$this->_tabindex_enabled) return 0;
$this->_tabindex_counter += 1;
return $this->_tabindex_counter;
}
function getCurrent()
{
if(!$this->_tabindex_enabled) return 0;
return $this->_tabindex_counter;
}
function resetTabindex($reset = 0)
{
$this->_tabindex_counter = $reset;
}
function get_attributes($options, $name = '', $value = '')
{
$ret = '';
//
foreach ($options as $option => $optval)
{
$optval = trim($optval);
switch ($option)
{
case 'id':
$ret .= $this->_format_id($optval, $name, $value);
break;
case 'class':
if(!empty($optval)) $ret .= " class='{$optval}'";
break;
case 'size':
if($optval) $ret .= " size='{$optval}'";
break;
case 'title':
if($optval) $ret .= " title='{$optval}'";
break;
case 'label':
if($optval) $ret .= " label='{$optval}'";
break;
case 'tabindex':
if($optval) $ret .= " tabindex='{$optval}'";
elseif(false === $optval || !$this->_tabindex_enabled) break;
else
{
$this->_tabindex_counter += 1;
$ret .= " tabindex='".$this->_tabindex_counter."'";
}
break;
case 'readonly':
if($optval) $ret .= " readonly='readonly'";
break;
case 'multiple':
if($optval) $ret .= " multiple='multiple'";
break;
case 'selected':
if($optval) $ret .= " selected='selected'";
break;
case 'checked':
if($optval) $ret .= " checked='checked'";
break;
case 'disabled':
if($optval) $ret .= " disabled='disabled'";
break;
case 'required':
if($optval) $ret .= " required='required'";
break;
case 'autofocus':
if($optval) $ret .= " autofocus='autofocus'";
break;
case 'placeholder':
if($optval) $ret .= " placeholder='{$optval}'";
break;
case 'autocomplete':
if($optval) $ret .= " autocomplete='{$optval}'";
break;
case 'pattern':
if($optval) $ret .= " pattern='{$optval}'";
break;
case 'other':
if($optval) $ret .= " $optval";
break;
}
if(substr($option,0,5) =='data-')
{
$ret .= " ".$option."='{$optval}'";
}
}
return $ret;
}
/**
* Auto-build field attribute id
*
* @param string $id_value value for attribute id passed with the option array
* @param string $name the name attribute passed to that field
* @param unknown_type $value the value attribute passed to that field
* @return string formatted id attribute
*/
function _format_id($id_value, $name, $value = '', $return_attribute = 'id')
{
if($id_value === false) return '';
//format data first
$name = trim($this->name2id($name), '-');
$value = trim(preg_replace('#[^a-zA-Z0-9\-]#','-', $value), '-');
//$value = trim(preg_replace('#[^a-z0-9\-]#/i','-', $value), '-'); // This should work - but didn't for me!
$value = trim(str_replace("/","-",$value), '-'); // Why?
if(!$id_value && is_numeric($value)) $id_value = $value;
// clean - do it better, this could lead to dups
$id_value = trim($id_value, '-');
if(empty($id_value) ) return " {$return_attribute}='{$name}".($value ? "-{$value}" : '')."'";// also useful when name is e.g. name='my_name[some_id]'
elseif(is_numeric($id_value) && $name) return " {$return_attribute}='{$name}-{$id_value}'";// also useful when name is e.g. name='my_name[]'
else return " {$return_attribute}='{$id_value}'";
}
function name2id($name)
{
$name = strtolower($name);
return rtrim(str_replace(array('[]', '[', ']', '_', '/', ' ','.'), array('-', '-', '', '-', '-', '-', '-'), $name), '-');
}
/**
* Format options based on the field type,
* merge with default
*
* @param string $type
* @param string $name form name attribute value
* @param array|string $user_options
* @return array merged options
*/
function format_options($type, $name, $user_options=null)
{
if(is_string($user_options))
{
parse_str($user_options, $user_options);
}
$def_options = $this->_default_options($type);
if(is_array($user_options))
{
$user_options['name'] = $name; //required for some of the automated tasks
foreach (array_keys($user_options) as $key)
{
if(!isset($def_options[$key]) && substr($key,0,5)!='data-') unset($user_options[$key]); // data-xxxx exempt //remove it?
}
}
else
{
$user_options = array('name' => $name); //required for some of the automated tasks
}
return array_merge($def_options, $user_options);
}
/**
* Get default options array based on the field type
*
* @param string $type
* @return array default options
*/
function _default_options($type)
{
if(isset($this->_cached_attributes[$type])) return $this->_cached_attributes[$type];
$def_options = array(
'id' => '',
'class' => '',
'title' => '',
'size' => '',
'readonly' => false,
'selected' => false,
'checked' => false,
'disabled' => false,
'required' => false,
'autofocus' => false,
'tabindex' => 0,
'label' => '',
'placeholder' => '',
'pattern' => '',
'other' => '',
'autocomplete' => ''
// 'multiple' => false, - see case 'select'
);
$form_control = (deftrue('BOOTSTRAP') === 3) ? ' form-control' : '';
switch ($type) {
case 'hidden':
$def_options = array('id' => false, 'disabled' => false, 'other' => '');
break;
case 'text':
$def_options['class'] = 'tbox input-text'.$form_control;
unset($def_options['selected'], $def_options['checked']);
break;
case 'file':
$def_options['class'] = 'tbox file';
unset($def_options['selected'], $def_options['checked']);
break;
case 'textarea':
$def_options['class'] = 'tbox textarea'.$form_control;
unset($def_options['selected'], $def_options['checked'], $def_options['size']);
break;
case 'select':
$def_options['class'] = 'tbox select'.$form_control;
$def_options['multiple'] = false;
unset($def_options['checked']);
break;
case 'option':
$def_options = array('class' => '', 'selected' => false, 'other' => '', 'disabled' => false, 'label' => '');
break;
case 'radio':
//$def_options['class'] = ' ';
unset($def_options['size'], $def_options['selected']);
break;
case 'checkbox':
unset($def_options['size'], $def_options['selected']);
break;
case 'submit':
$def_options['class'] = 'button';
unset($def_options['checked'], $def_options['selected'], $def_options['readonly']);
break;
case 'submit_image':
$def_options['class'] = 'action';
unset($def_options['checked'], $def_options['selected'], $def_options['readonly']);
break;
case 'admin_button':
unset($def_options['checked'], $def_options['selected'], $def_options['readonly']);
break;
}
$this->_cached_attributes[$type] = $def_options;
return $def_options;
}
function columnSelector($columnsArray, $columnsDefault = '', $id = 'column_options')
{
$columnsArray = array_filter($columnsArray);
$text = '
";
// $text .= "