Example #1
0
 function datetime($name, $value)
 {
     $values = split(" ", $value);
     $return = Form::date($name, $values[0]);
     $return .= " - ";
     $return .= Form::time($name, $values[1]);
     return $return;
 }
Example #2
0
    public static function date($field_id, $field_setup)
    {
        $field_setup['attr']['type'] = 'text';
        $field_setup['attr']['id'] = Form::valid_attr_id($field_id);
        $field_setup['attr']['name'] = $field_id;
        $field_setup['attr']['class'] = 'singleline_textfield widget_datepicker' . ($field_setup['metas']['range'] === TRUE ? ' widget_datepicker_range' : NULL) . ' ' . $field_setup['attr']['class'];
        $field_setup['attr']['months'] = empty($field_setup['metas']['months']) ? 1 : $field_setup['metas']['months'];
        $field_setup['metas']['format'] = empty($field_setup['metas']['format']) ? 'day.month.year' : $field_setup['metas']['format'];
        // date range request
        if ($field_setup['metas']['range'] === TRUE) {
            if ($field_setup['metas']['time']) {
                list($field_setup['value'][0], $time_from) = Format::string_explode($field_setup['value'][0], ' ');
                list($field_setup['value'][1], $time_to) = Format::string_explode($field_setup['value'][1], ' ');
            }
            $field_setup['attr']['name'] = Form::valid_attr_id($field_id) . '_from';
            $field_setup['attr']['id'] = Form::valid_attr_id($field_id) . '_from';
            $field_setup['attr']['value'] = empty($field_setup['value'][0]) ? NULL : Format::date($field_setup['value'][0], 'human', Format::prepare_date_format($field_setup['metas']['format'], 'php'));
            $from_field = '<input' . Html::attributes($field_setup['attr']) . '>';
            $widget_from = Form::label(Form::valid_attr_id($field_id) . '_from', $field_setup['label']['from'] . ':' . Form::field_mark($field_id, $field_setup)) . '<br>' . $from_field;
            $field_setup['attr']['name'] = Form::valid_attr_id($field_id) . '_to';
            $field_setup['attr']['id'] = Form::valid_attr_id($field_id) . '_to';
            $field_setup['attr']['value'] = empty($field_setup['value'][1]) ? NULL : Format::date($field_setup['value'][1], 'human', Format::prepare_date_format($field_setup['metas']['format'], 'php'));
            $to_field = '<input' . Html::attributes($field_setup['attr']) . '>';
            $widget_to = Form::label(Form::valid_attr_id($field_id) . '_to', $field_setup['label']['to'] . ':' . Form::field_mark($field_id, $field_setup)) . '<br>' . $to_field;
            if ($field_setup['metas']['time']) {
                $widget = '
					<div class="fl mr">
						' . $widget_from . '
					</div>
					<div class="fl mr">
						<br>' . Form::time($field_id . '_from_time', array('value' => $time_from, 'attr' => array('class' => 'widget_datepicker_time'), 'metas' => $field_setup['metas']['time']['start'])) . '
					</div>
					<div class="fl mr">
						' . $widget_to . '
					</div>
					<div class="fl">
						<br>' . Form::time($field_id . '_to_time', array('value' => $time_to, 'attr' => array('class' => 'widget_datepicker_time'), 'metas' => $field_setup['metas']['time']['end'])) . '
					</div>
					';
            } else {
                $widget = '
					<div class="fl mr">
						' . $widget_from . '
					</div>
					<div class="fl">
						' . $widget_to . '
					</div>
					';
            }
        } else {
            if ($field_setup['metas']['time']) {
                list($field_setup['value'], $time) = Format::string_explode($field_setup['value'], ' ');
                $field_setup['attr']['value'] = empty($field_setup['value']) ? NULL : Format::date($field_setup['value'], 'human', Format::prepare_date_format($field_setup['metas']['format'], 'php'));
                $field_setup['attr']['class'] = 'widget_datepicker_datetime ' . $field_setup['attr']['class'];
                $from_field = '<input' . Html::attributes($field_setup['attr']) . '>';
                $widget = '
					<div class="fl mr">
						' . Form::label(Form::valid_attr_id($field_id), $field_setup['label'] . ':' . Form::field_mark($field_id, $field_setup)) . '<br>' . $from_field . '
					</div>
					<div class="fl">
						<br>' . Form::time($field_id . '_time', array('value' => $time, 'attr' => array('class' => 'widget_datepicker_time'), 'metas' => $field_setup['metas']['time'])) . '
					</div>
					';
            } else {
                $field_setup['attr']['value'] = Format::date($field_setup['value'], 'human', Format::prepare_date_format($field_setup['metas']['format'], 'php'));
                $widget = '<input' . Html::attributes($field_setup['attr']) . '>';
            }
        }
        // cache required assets
        if (empty($field_setup['metas']['readonly'])) {
            Session::cache('js', 'system::plugins/ui/jquery.ui.datepicker.min.js');
            Session::cache('jsinline', Form::valid_attr_id($field_id) . '_dates = $("' . ($field_setup['metas']['range'] === TRUE ? '#' . Form::valid_attr_id($field_id) . '_from, #' . Form::valid_attr_id($field_id) . '_to' : '#' . $field_setup['attr']['id']) . '").datepicker({' . ($field_setup['metas']['range'] === TRUE ? ' onSelect : function(selectedDate) { system.form.date_range(selectedDate, "' . Form::valid_attr_id($field_id) . '", this, $(this)); },' : NULL) . ' changeMonth: true, changeYear: true, showWeek : true, firstDay : 1, numberOfMonths : ' . $field_setup['attr']['months'] . ', showButtonPanel : false, dateFormat: "' . Format::prepare_date_format($field_setup['metas']['format'], 'js') . '" })');
        }
        return $widget;
    }
Example #3
0
Html::macro("configForm", function ($type, $model, $field, $showDesc = false, $selectArray = null, $multiple = false) {
    if ($type == "text") {
        $b = Form::text($field, $model->{$field}, ['placeholder' => trans_choice('admin.' . $field, 1), 'id' => $field]);
    } else {
        if ($type == "textarea") {
            $b = Form::textarea($field, $model->{$field}, ['placeholder' => trans_choice('admin.' . $field, 1), 'id' => $field]);
        } else {
            if ($type == "email") {
                $b = Form::email($field, $model->{$field}, ['placeholder' => trans_choice('admin.' . $field, 1), 'id' => $field]);
            } else {
                if ($type == "date") {
                    $b = Form::date($field, $model->{$field}, ['placeholder' => trans_choice('admin.' . $field, 1), 'id' => $field]);
                } else {
                    if ($type == "time") {
                        $b = Form::time($field, $model->{$field}, ['placeholder' => trans_choice('admin.' . $field, 1), 'id' => $field]);
                    } else {
                        if ($type == "url") {
                            $b = Form::url($field, $model->{$field}, ['placeholder' => trans_choice('admin.' . $field, 1), 'id' => $field]);
                        } else {
                            if ($type == "number") {
                                $b = Form::number($field, $model->{$field}, ['placeholder' => trans_choice('admin.' . $field, 1), 'id' => $field]);
                            } else {
                                if ($type == "color") {
                                    $b = Form::color($field, $model->{$field}, ['placeholder' => trans_choice('admin.' . $field, 1), 'id' => 'colorpicker']);
                                    $b .= Form::text($field, $model->{$field}, ['placeholder' => trans_choice('admin.' . $field, 1), 'id' => $field]);
                                } else {
                                    if ($type == "select" && !$multiple) {
                                        $b = Form::select($field, $selectArray, $model->{$field}, ['id' => $field]);
                                    } else {
                                        if ($type == "select" && $multiple) {
Example #4
0
            $options['checked'] = 'checked';
        }
        $input = '<div class="checkbox">' . Form::input($type, $name, 1, $options) . '</div>';
    } else {
        if ($type == 'static') {
            $value = Form::getValueAttribute($name, $value);
            $input = '<p class="form-control-static">' . $value . '</p>';
        } else {
            $input = Form::$type($name, $value, $options);
        }
    }
    $data = array('label' => Form::label($name, $title, array('class' => 'col-sm-3 control-label')), 'input' => $input, 'field' => $name);
    return View::make('macros/form_control', $data);
});
Form::macro('date', function ($name, $value = null, $options = array()) {
    $value = Form::getValueAttribute($name, $value);
    if (is_object($value) && 'Carbon\\Carbon' == get_class($value)) {
        $value = $value->toDateString();
    }
    return Form::input('date', $name, $value, $options);
});
Form::macro('time', function ($name, $value = null, $options = array()) {
    $value = Form::getValueAttribute($name, $value);
    if (is_object($value) && 'Carbon\\Carbon' == get_class($value)) {
        $value = $value->format('H:i');
    }
    return Form::input('time', $name, $value, array('class' => 'span2'));
});
Form::macro('datetime', function ($name, $value = null, $options = array()) {
    return Form::date($name, $value, $options) . Form::time($name, $value, $options);
});
Example #5
0
 private static function obj_and_sess_destroy()
 {
     $_POST = array();
     $_GET = array();
     $_SESSION = array();
     unset($_COOKIE[session_name()]);
     session_destroy();
     self::$time = 0;
     self::$errCount = 0;
     self::$errMessage = "";
     self::$formConfig = array();
     self::$sourceData = array();
     exit;
 }
 function test_generates_time_inputs()
 {
     $this->assertTemplate('forms/time', Form::time('clocks'));
 }