Exemple #1
0
function stddatefstr($date)
{
    if ($date != null) {
        return timefstr("Y-m-d", $date);
    } else {
        return null;
    }
}
Exemple #2
0
function form_input($form_id, $class, $object, $field, $type, $args = array())
{
    if (!isset($args['nolabel']) || $args['nolabel'] === false) {
        echo "<div class=\"row\">\n";
    }
    if (isset($args['nameid']) && $args['nameid'] == true) {
        $name = $field . "-" . $form_id;
    } else {
        $name = $field;
    }
    if (isset($args['array']) && $args['array'] == true) {
        $name = $name . "[]";
    }
    if ($type != "pick_multiple") {
        if (!isset($args['nolabel']) || $args['nolabel'] === false) {
            echo '<label for="' . esc_attr($form_id . '-' . $field) . '">';
            $fieldLabel = $field;
            if (substr($field, -2) == "Id") {
                $fieldLabel = substr($field, 0, -2);
            }
            echo esc_html(\i18n($class . "." . $fieldLabel));
            echo "</label>\n";
        }
    }
    $required = "";
    if (isset($args['required']) && $args['required']) {
        $required = ' required="true"';
    }
    switch ($type) {
        case 'string':
            echo '<input id="' . esc_attr($form_id . '-' . $field) . '" type="text" name="' . esc_attr($name) . '"';
            if ($object != NULL) {
                echo ' value="' . esc_attr($object->{$field}) . '"';
            }
            echo "{$required} />\n";
            break;
        case 'text':
            echo '<textarea id="' . esc_attr($form_id . '-' . $field) . '" name="' . esc_attr($name) . '">';
            if ($object != NULL) {
                echo esc_html($object->{$field});
            }
            echo '</textarea>';
            break;
        case 'numeric':
            echo '<input id="' . esc_attr($form_id . '-' . $field) . '" type="numeric" name="' . esc_attr($name) . '"';
            if ($object != NULL) {
                echo ' value="' . esc_attr($object->{$field}) . '"';
            }
            echo "{$required} />\n";
            break;
        case 'boolean':
            echo '<input id="' . esc_attr($form_id . '-' . $field) . '" type="checkbox" name="' . esc_attr($name) . '"';
            if ($object != NULL) {
                if ($object->{$field}) {
                    echo ' checked="checked"';
                }
            } else {
                if (!isset($args['default']) || $args['default'] == TRUE) {
                    echo ' checked="checked"';
                }
            }
            echo " />\n";
            break;
        case 'float':
            if (!isset($args['step'])) {
                $step = 0.01;
            } else {
                $step = $args['step'];
            }
            echo '<input id="' . esc_attr($form_id . '-' . $field) . '" type="number" step="' . esc_attr($step) . '" min="0.00" name="' . esc_attr($name) . '"';
            if ($object != NULL) {
                echo ' value="' . esc_attr($object->{$field}) . '"';
            }
            echo "{$required} />\n";
            break;
        case 'date':
            // Class dateinput will be catched to show js date picker
            echo '<input id="' . esc_attr($form_id . '-' . $field) . '" type="text" class="dateinput" name="' . esc_attr($name) . '"';
            if ($object !== null) {
                if (isset($args['dataformat'])) {
                    if ($args['dataformat'] == 'standard') {
                        $timestamp = stdtimefstr($object->{$field});
                    } else {
                        $timestamp = timefstr($args['dataformat'], $object->{$field});
                    }
                } else {
                    $timestamp = $object->{$field};
                }
                echo ' value="' . esc_attr(\i18nDate($timestamp)) . '"';
            }
            echo "{$required} />\n";
            break;
        case 'pick':
            $model = $args['model'];
            $data = $args['data'];
            if ($model !== null) {
                switch ($model) {
                    case 'Category':
                        $data = CategoriesService::getAll(false);
                        break;
                    case 'Provider':
                        $data = ProvidersService::getAll();
                        break;
                    case 'TaxCategory':
                        $data = TaxesService::getAll();
                        break;
                    case 'Tax':
                        $cats = TaxesService::getAll();
                        $data = array();
                        foreach ($cats as $cat) {
                            $data[] = $cat->getCurrentTax();
                        }
                        break;
                    case 'CustTaxCat':
                        $data = CustTaxCatsService::getAll();
                        break;
                    case 'Role':
                        $data = RolesService::getAll();
                        break;
                    case 'Attribute':
                        $data = AttributesService::getAllAttrs();
                        break;
                    case 'AttributeSet':
                        $data = AttributesService::getAll();
                        break;
                    case 'Location':
                        $locSrv = new LocationsService();
                        $data = $locSrv->getAll();
                        break;
                    case 'DiscountProfile':
                        $profSrv = new DiscountProfilesService();
                        $data = $profSrv->getAll();
                        break;
                    case 'TariffArea':
                        $areaSrv = new TariffAreasService();
                        $data = $areaSrv->getAll();
                        break;
                }
            }
            echo '<select id="' . esc_attr($form_id . '-' . $field) . '" name="' . esc_attr($name) . '">';
            if (isset($args['nullable']) && $args['nullable']) {
                echo '<option value=""></option>';
            }
            foreach ($data as $r) {
                $selected = "";
                $r_id = $r->id;
                $r_label = $r->label;
                if ($model == null) {
                    $r_id = $r['id'];
                    $r_label = $r['label'];
                }
                if ($object != NULL && ($object->{$field} == $r_id || is_object($object->{$field}) && $object->{$field}->id == $r_id)) {
                    $selected = ' selected="true"';
                }
                echo '<option value="' . esc_attr($r_id) . '"' . $selected . '>' . esc_html($r_label) . '</option>';
            }
            echo "</select>\n";
            break;
        case 'pick_multiple':
            $model = $args['model'];
            switch ($model) {
                case 'Category':
                    $data = CategoriesService::getAll();
                    break;
            }
            foreach ($data as $r) {
                $selected = "";
                if ($object != NULL && array_search($r->id, $object->{$field}) !== FALSE) {
                    $selected = ' checked="true"';
                }
                $id = $form_id . "-" . $field . "-" . $r->id;
                echo '<label for="' . esc_attr($id) . '">' . esc_html($r->label) . '</label>';
                echo '<input id="' . esc_attr($id) . '" type="checkbox" name="' . esc_attr($name) . '[]" value="' . esc_attr($r->id) . '"' . $selected . "/>\n";
            }
            break;
    }
    if (!isset($args['nolabel']) || $args['nolabel'] === false) {
        echo "</div>";
    }
}
Exemple #3
0
 public function revDatetime($datetime)
 {
     return timefstr($this->entries['datetime'], $datetime);
 }