Ejemplo n.º 1
0
 public function htmlForValue($field_value, $input_name = null)
 {
     $field_name = $this->getFieldName();
     $html = '';
     $options = '';
     if (is_null($input_name)) {
         $input_name = $field_name;
     }
     $options_arr = $this->getOptionsArr();
     foreach ($options_arr as $value => $title) {
         $selected_html_attr = '';
         if ($field_value == $value) {
             $selected_html_attr = ' selected';
         }
         $options .= '<option value="' . $value . '"' . $selected_html_attr . '>' . $title . '</option>';
     }
     $is_null_checked = '';
     if (is_null($field_value)) {
         $is_null_checked = ' checked ';
     }
     $is_required_str = '';
     if ($this->is_required) {
         $is_required_str = ' required ';
     }
     $html .= '<div class="input-group">';
     $html .= '<select name="' . $input_name . '" class="form-control" ' . $is_required_str . '>' . $options . '</select>';
     if ($this->getShowNullCheckbox()) {
         $html .= '<div class="input-group-addon">';
         $html .= '<input type = "checkbox" value="1" name="' . Sanitize::sanitizeAttrValue($input_name) . '___is_null" ' . $is_null_checked . ' /> null';
         $html .= '</div>';
     }
     $html .= '</div>';
     return $html;
 }
Ejemplo n.º 2
0
 /**
  * Returns sanitized content.
  * @param $obj
  * @return string
  */
 public function html($obj)
 {
     $value = CRUDCompiler::compile($this->getValue(), ['this' => $obj]);
     $html = "UNDEFINED";
     $options_arr = $this->getOptionsArr();
     if (array_key_exists($value, $options_arr)) {
         $html = $options_arr[$value];
     }
     return Sanitize::sanitizeTagContent($html);
 }
Ejemplo n.º 3
0
 public static function hiddenFieldHtml($field_name, $field_value)
 {
     $is_null_value = '';
     if (is_null($field_value)) {
         $is_null_value = '1';
     }
     $html = '';
     $html .= '<input type="hidden" name="' . Sanitize::sanitizeAttrValue($field_name) . '" value="' . Sanitize::sanitizeAttrValue($field_value) . '"/>';
     $html .= '<input type="hidden" name="' . Sanitize::sanitizeAttrValue($field_name) . '___is_null" value="' . Sanitize::sanitizeAttrValue($is_null_value) . '"/>';
     return $html;
 }
Ejemplo n.º 4
0
 public function html($obj)
 {
     $field_name = $this->getFieldName();
     $field_value = CRUDFieldsAccess::getObjectFieldValue($obj, $field_name);
     $is_required_str = '';
     if ($this->is_required) {
         $is_required_str = ' required ';
     }
     $disabled = '';
     if ($this->getDisabled()) {
         $disabled = 'disabled';
     }
     return '<textarea name="' . Sanitize::sanitizeAttrValue($field_name) . '"  ' . $is_required_str . ' class="form-control" rows="5"  ' . $disabled . '>' . Sanitize::sanitizeTagContent($field_value) . '</textarea>';
 }
Ejemplo n.º 5
0
 public function html($obj)
 {
     Assert::assert($obj);
     $o = '';
     $o .= '<form style="display: inline;" method="post" action="' . \OLOG\Url::getCurrentUrl() . '">';
     $o .= Operations::operationCodeHiddenField(CRUDTable::OPERATION_DELETE_MODEL);
     $o .= '<input type="hidden" name="' . self::FIELD_CLASS_NAME . '" value="' . Sanitize::sanitizeAttrValue(get_class($obj)) . '">';
     $o .= '<input type="hidden" name="' . self::FIELD_OBJECT_ID . '" value="' . Sanitize::sanitizeAttrValue(CRUDFieldsAccess::getObjId($obj)) . '">';
     if ($this->redirect_after_delete_url != '') {
         $o .= '<input type="hidden" name="' . self::FIELD_REDIRECT_AFTER_DELETE_URL . '" value="' . Sanitize::sanitizeAttrValue($this->redirect_after_delete_url) . '">';
     }
     $o .= '<button class="' . $this->button_class_str . '" type="submit" onclick="return window.confirm(\'Delete?\');">' . $this->button_text . '</button>';
     $o .= '</form>';
     return $o;
 }
 public function html($obj)
 {
     Assert::assert($obj);
     $title_field_name = $this->getTitleFieldName();
     $obj_title = CRUDFieldsAccess::getObjectFieldValue($obj, $title_field_name);
     $id_field_name = $this->getIdFieldName();
     if ($id_field_name == '') {
         $id = CRUDFieldsAccess::getObjId($obj);
     } else {
         $id = CRUDFieldsAccess::getObjectFieldValue($obj, $id_field_name);
     }
     $o = '';
     $o .= '<button class="btn btn-xs btn-default js-ajax-form-select" type="submit" data-id="' . Sanitize::sanitizeAttrValue($id) . '" data-title="' . Sanitize::sanitizeAttrValue($obj_title) . '">Выбор</button>';
     return $o;
 }
Ejemplo n.º 7
0
 /**
  * @param $arr
  * @param $path
  * @return mixed
  * @throws \Exception
  */
 public static function getRequiredSubvalue($arr, $path)
 {
     Assert::assert(!empty($path));
     Assert::assert(is_array($arr));
     $value = $arr;
     $parts = explode(".", $path);
     foreach ($parts as $part) {
         if (isset($value[$part])) {
             $value = $value[$part];
         } else {
             throw new \Exception('missing config key: ' . \OLOG\Sanitize::sanitizeTagContent($path));
         }
     }
     return $value;
 }
Ejemplo n.º 8
0
 public static function renderTabs(array $tabs_arr)
 {
     echo '<ul class="nav nav-tabs">';
     foreach ($tabs_arr as $tab_arr) {
         $classes = '';
         // TODO: код взят из Router::match3() - использовать общую реализацию?
         $url_regexp = '@^' . $tab_arr['MATCH_URL'] . '$@';
         $matches_arr = array();
         $current_url = \OLOG\Router::uri_no_getform();
         if (preg_match($url_regexp, $current_url, $matches_arr)) {
             $classes .= ' active ';
         }
         echo '<li role="presentation" class="' . Sanitize::sanitizeAttrValue($classes) . '"><a href="' . Sanitize::sanitizeUrl($tab_arr['LINK_URL']) . '">' . Sanitize::sanitizeTagContent($tab_arr['TITLE']) . '</a></li>';
     }
     echo '</ul>';
 }
Ejemplo n.º 9
0
 public function action()
 {
     Auth::logout();
     // remove extra cookies
     if (!empty(AuthConfig::getExtraCookiesArr())) {
         $extra_cookies_arr = AuthConfig::getExtraCookiesArr();
         foreach ($extra_cookies_arr as $cookie_name => $cookie_value) {
             //setcookie($cookie_name, $cookie_value, time() + Auth::SESSION_LIFETIME_SECONDS, '/', Auth::sessionCookieDomain());
             setcookie($cookie_name, "", 1000, '/', Auth::sessionCookieDomain(), false, true);
         }
     }
     $redirect = '/';
     if (isset($_GET['destination'])) {
         $redirect = Sanitize::sanitizeUrl($_GET['destination']);
     }
     \OLOG\Redirects::redirect($redirect);
 }
Ejemplo n.º 10
0
    public function html($obj)
    {
        static $CRUDFormWidgetMediumEditor_include_script;
        $field_name = $this->getFieldName();
        $field_value = CRUDFieldsAccess::getObjectFieldValue($obj, $field_name);
        /* Нужно изменить на нах CDN */
        $script = '';
        $uniqid = $this->getUniqid();
        if (!isset($CRUDFormWidgetMediumEditor_include_script)) {
            $script = '
				<script src="//cdnjs.cloudflare.com/ajax/libs/medium-editor/5.22.0/js/medium-editor.min.js"></script>
				<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/medium-editor/5.22.0/css/medium-editor.min.css" type="text/css" media="screen" charset="utf-8">
				<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/medium-editor/5.22.0/css/themes/default.min.css" type="text/css" media="screen" charset="utf-8">			';
            $CRUDFormWidgetMediumEditor_include_script = false;
        }
        $html = '';
        $html .= '<textarea id="' . $uniqid . '_textarea" name="' . Sanitize::sanitizeAttrValue($field_name) . '" style="display: none;">' . $field_value . '</textarea>';
        $html .= '<div id="' . $uniqid . '" class="form-control" style="height: auto;">' . $field_value . '</div>';
        ob_start();
        ?>
			<script>
				var <?php 
        echo $uniqid;
        ?>
 = new MediumEditor("#<?php 
        echo $uniqid;
        ?>
", {
					placeholder: false
				});

                <?php 
        echo $uniqid;
        ?>
.subscribe('editableInput', function (event, editable) {
					var content = $(editable).html();
					$('#<?php 
        echo $uniqid;
        ?>
_textarea').val(content).trigger('MediumEditor.change');
				});
			</script>
		<?php 
        $html .= ob_get_clean();
        return $script . $html;
    }
Ejemplo n.º 11
0
 /**
  * @param $obj InterfaceWeight
  * @return string
  */
 public function html($obj)
 {
     Assert::assert($obj);
     $o = '';
     $o .= '<form style="display: inline;" method="post" action="' . \OLOG\Url::getCurrentUrl() . '">';
     $o .= Operations::operationCodeHiddenField(CRUDTable::OPERATION_SWAP_MODEL_WEIGHT);
     $o .= '<input type="hidden" name="' . self::FORMFIELD_CONTEXT_FIELDS_NAME . '" value="' . Sanitize::sanitizeAttrValue(implode(',', array_keys($this->context_fields_arr))) . '">';
     foreach ($this->context_fields_arr as $context_field_name => $context_field_value) {
         $context_field_value = CRUDCompiler::compile($context_field_value, ['this' => $obj]);
         $o .= NullablePostFields::hiddenFieldHtml($context_field_name, $context_field_value);
     }
     $o .= '<input type="hidden" name="_class_name" value="' . Sanitize::sanitizeAttrValue(get_class($obj)) . '">';
     $o .= '<input type="hidden" name="_id" value="' . Sanitize::sanitizeAttrValue(CRUDFieldsAccess::getObjId($obj)) . '">';
     $o .= '<button class="' . $this->button_class_str . '" type="submit">' . $this->button_text . '</button>';
     $o .= '</form>';
     return $o;
 }
Ejemplo n.º 12
0
    public function html($obj)
    {
        $field_name = $this->getFieldName();
        $field_value = CRUDFieldsAccess::getObjectFieldValue($obj, $field_name);
        $editor_element_id = 'editor_' . time() . '_' . rand(1, 999999);
        $html = '';
        $html .= '
            <style>
             #' . $editor_element_id . ' {
                position: relative;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        height: 500px;
            }
            </style>
            ';
        // TODO: is form-control needed?
        $html .= '<div id="' . $editor_element_id . '" class="form-control">' . Sanitize::sanitizeTagContent($field_value) . '</div>';
        $html .= '<textarea id="' . $editor_element_id . '_target" name="' . Sanitize::sanitizeAttrValue($field_name) . '" style="display: none;">' . Sanitize::sanitizeTagContent($field_value) . '</textarea>';
        // TODO: multiple insertion!!!!
        $html .= '<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.3/ace.js" type="text/javascript" charset="utf-8"></script>
            <script>
            //var editor_element = document.getElementById("' . $editor_element_id . '");
            //editor_element.parentElement.style.height = "500px";
            var editor = ace.edit("' . $editor_element_id . '");

            // TODO: enable another modes
            editor.getSession().setMode("ace/mode/html");

            editor.getSession().on("change", function() {
                var target = document.getElementById("' . $editor_element_id . '_target");
                //var editor_element = document.getElementById("' . $editor_element_id . '");
                target.innerHTML = editor.getSession().getValue();
            });
            </script>
            ';
        return $html;
    }
Ejemplo n.º 13
0
 public static function html($model_class_name, $create_form_html, $column_obj_arr, $parent_id_field_name, $order_by = '', $table_id = '1', $filters_arr = [], $col_with_padding_index = 0, $filters_position = CRUDTable::FILTERS_POSITION_NONE)
 {
     // TODO: придумать способ автогенерации table_id, который был бы уникальным, но при этом один и тот же когда одну таблицу запрашиваешь несколько раз
     CRUDTable::executeOperations();
     $objs_ids_arr = CRUDInternalTableObjectsSelector::getRecursiveObjIdsArrForClassName($model_class_name, $parent_id_field_name, $filters_arr, $order_by);
     //
     // вывод таблицы
     //
     $table_container_element_id = 'tableContainer_' . $table_id;
     // оборачиваем в отдельный div для выдачи только таблицы аяксом - иначе корневой элемент документа не будет доступен в jquery селекторах
     $html = '<div>';
     $html .= '<div class="' . $table_container_element_id . ' row">';
     if ($filters_position == CRUDTable::FILTERS_POSITION_LEFT) {
         $html .= '<div class="col-sm-4">';
         $html .= self::filtersHtml($filters_arr);
         $html .= '</div>';
         $html .= '<div class="col-sm-8">';
     } else {
         $html .= '<div class="col-sm-12">';
     }
     $html .= self::toolbarHtml($table_id, $create_form_html);
     if ($filters_position == CRUDTable::FILTERS_POSITION_TOP) {
         $html .= self::filtersHtml($filters_arr);
     }
     $html .= '<table class="table table-hover">';
     $html .= '<thead>';
     $html .= '<tr>';
     /** @var InterfaceCRUDTableColumn $column_obj */
     foreach ($column_obj_arr as $column_obj) {
         Assert::assert($column_obj instanceof InterfaceCRUDTableColumn);
         $html .= '<th>' . Sanitize::sanitizeTagContent($column_obj->getTitle()) . '</th>';
     }
     $html .= '</tr>';
     $html .= '</thead>';
     $html .= '<tbody>';
     foreach ($objs_ids_arr as $obj_data) {
         $obj_id = $obj_data['id'];
         $obj_obj = CRUDObjectLoader::createAndLoadObject($model_class_name, $obj_id);
         $html .= '<tr>';
         /** @var InterfaceCRUDTableColumn $column_obj */
         foreach ($column_obj_arr as $col_index => $column_obj) {
             Assert::assert($column_obj instanceof InterfaceCRUDTableColumn);
             /** @var InterfaceCRUDTableWidget $widget_obj */
             $widget_obj = $column_obj->getWidgetObj();
             Assert::assert($widget_obj);
             Assert::assert($widget_obj instanceof InterfaceCRUDTableWidget);
             $col_width_attr = '';
             if ($widget_obj instanceof CRUDTableWidgetDelete) {
                 $col_width_attr = ' width="1px" ';
             }
             if ($widget_obj instanceof CRUDTableWidgetWeight) {
                 $col_width_attr = ' width="1px" ';
             }
             $html .= '<td ' . $col_width_attr . '>';
             if ($col_index == $col_with_padding_index) {
                 $html .= '<div style="padding-left: ' . $obj_data['depth'] * 30 . 'px;">';
             }
             $html .= $widget_obj->html($obj_obj);
             if ($col_index == 0) {
                 $html .= '</div>';
             }
             $html .= '</td>';
         }
         $html .= '</tr>';
     }
     $html .= '</tbody>';
     $html .= '</table>';
     $html .= '</div>';
     $html .= '</div>';
     $html .= '</div>';
     // Загрузка скриптов
     $html .= CRUDTableScript::getHtml($table_container_element_id, Url::getCurrentUrlNoGetForm());
     return $html;
 }
Ejemplo n.º 14
0
    public function html($obj)
    {
        $field_name = $this->getFieldName();
        $referenced_class_name = $this->getReferencedClassName();
        $referenced_class_title_field = $this->getReferencedClassTitleField();
        $field_value = CRUDFieldsAccess::getObjectFieldValue($obj, $field_name);
        $options_html_arr = ['<option value=""></option>'];
        // TODO: check referenced class interfaces
        $referenced_obj_ids_arr = \OLOG\DB\DBWrapper::readColumn($referenced_class_name::DB_ID, 'select ID from ' . $referenced_class_name::DB_TABLE_NAME . ' order by ID');
        $options_arr = [];
        foreach ($referenced_obj_ids_arr as $id) {
            $obj = CRUDObjectLoader::createAndLoadObject($referenced_class_name, $id);
            $options_arr[$id] = CRUDFieldsAccess::getObjectFieldValue($obj, $referenced_class_title_field);
        }
        foreach ($options_arr as $value => $title) {
            $selected_html_attr = '';
            if ($field_value == $value) {
                $selected_html_attr = ' selected';
            }
            $options_html_arr[] = '<option value="' . $value . '"' . $selected_html_attr . '>' . $title . '</option>';
            // TODO: sanitize
        }
        $html = '';
        $select_element_id = 'js_select_' . rand(1, 999999);
        $html .= '<select id="' . Sanitize::sanitizeAttrValue($select_element_id) . '" name="' . Sanitize::sanitizeAttrValue($field_name) . '" class="form-control">' . implode('', $options_html_arr) . '</select>';
        $html .= '<input type="hidden" id="' . Sanitize::sanitizeAttrValue($select_element_id) . '_is_null" name="' . Sanitize::sanitizeAttrValue($field_name) . '___is_null"/>';
        ob_start();
        ?>
        <script>
            var select_element = document.getElementById('<?php 
        echo $select_element_id;
        ?>
');
            select_element.addEventListener(
                'change',
                function(){
                    var select_element_id = document.getElementById('<?php 
        echo $select_element_id;
        ?>
');
                    var is_null_element = document.getElementById('<?php 
        echo $select_element_id;
        ?>
_is_null');
                    var value = select_element_id.options[select_element_id.selectedIndex].value;

                    if (value == ''){
                        is_null_element.value = '1';
                    } else {
                        is_null_element.value = '';
                    }
                }
            );

            select_element.dispatchEvent(new Event('change')); // fire to initialize is_null input on display
        </script>

        <?php 
        $html .= ob_get_clean();
        return $html;
    }
Ejemplo n.º 15
0
    public static function render($message = '', $show_form = true)
    {
        $message_type = 'danger';
        ?>
        <style>
            body {
                padding-top: 40px;
                padding-bottom: 40px;
                background-color: #eee;
            }

            .form-signin {
                max-width: 330px;
                padding: 15px;
                margin: 0 auto;
            }
            .form-signin .form-signin-heading,
            .form-signin .checkbox {
                margin-bottom: 10px;
            }
            .form-signin .checkbox {
                font-weight: normal;
            }
            .form-signin .form-control {
                position: relative;
                height: auto;
                -webkit-box-sizing: border-box;
                -moz-box-sizing: border-box;
                box-sizing: border-box;
                padding: 10px;
                font-size: 16px;
            }
            .form-signin .form-control:focus {
                z-index: 2;
            }
            .form-signin input[type="password"] {
                margin-bottom: 10px;
                border-top-left-radius: 0;
                border-top-right-radius: 0;
            }
        </style>

        <form class="form-signin" method="post" action="<?php 
        LoginAction::getUrl();
        ?>
">
            <h2 class="form-signin-heading">Please sign in</h2>
            <?php 
        if ($message) {
            ?>
                <div class="alert alert-<?php 
            echo $message_type;
            ?>
 width-370" role="alert"><?php 
            echo $message;
            ?>
</div>
            <?php 
        }
        if ($show_form) {
            $success_redirect_url = GETAccess::getOptionalGetValue('success_redirect_url', '');
            if ($success_redirect_url != '') {
                echo '<input type="hidden" name="success_redirect_url" value="' . Sanitize::sanitizeAttrValue($success_redirect_url) . '"/>';
            }
            ?>
            <label for="inputEmail" class="sr-only">Email address</label>
            <input style="margin-bottom: -1px; border-bottom-right-radius: 0; border-bottom-left-radius: 0;" name="login" class="form-control" placeholder="login" required autofocus>
            <label for="inputPassword" class="sr-only">Password</label>
            <input type="password" name="password" class="form-control" placeholder="Password" required>
            <!--
            <div class="checkbox">
                <label>
                    <input type="checkbox" value="remember-me"> Remember me
                </label>
            </div>
            -->
            <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>

            <?php 
        }
        ?>
        </form>
        <?php 
        //}
    }
Ejemplo n.º 16
0
    public function htmlForValue($field_value, $input_name = null)
    {
        $field_name = $this->getFieldName();
        if (is_null($input_name)) {
            $input_name = $field_name;
        }
        $uniqid = uniqid('CRUDFormWidgetRadios_');
        $input_cols = $this->getShowNullCheckbox() ? '10' : '12';
        $html = '';
        //$html .= '<div class="row">';
        //$html .= '<div class="col-sm-' . $input_cols . '" id="' . $uniqid . '_radio_box">';
        $html .= '<div id="' . $uniqid . '_radio_box">';
        $options_arr = $this->getOptionsArr();
        $disabled = '';
        if ($this->getDisabled()) {
            $disabled = 'disabled';
        }
        foreach ($options_arr as $value => $title) {
            $selected_html_attr = '';
            if (!is_null($field_value) && $field_value == $value) {
                $selected_html_attr = ' checked ';
            }
            $is_required_str = '';
            if ($this->is_required) {
                $is_required_str = ' required ';
            }
            $html .= '<label class="radio-inline"><input type="radio" name="' . Sanitize::sanitizeAttrValue($input_name) . '" value="' . Sanitize::sanitizeAttrValue($value) . '" ' . $selected_html_attr . ' ' . $is_required_str . ' ' . $disabled . '> ' . $title . '</label>';
        }
        //$html .= '</div>';
        if ($this->getShowNullCheckbox()) {
            $is_null_checked = '';
            if (is_null($field_value)) {
                $is_null_checked = ' checked ';
            }
            ob_start();
            ?>
                <label class="radio-inline">
                    <input id="<?php 
            echo $uniqid;
            ?>
___is_null" type="checkbox" value="1" name="<?php 
            echo Sanitize::sanitizeAttrValue($input_name);
            ?>
___is_null" <?php 
            echo $is_null_checked;
            ?>
> NULL
                </label>
            <script>
                (function () {
                    var $input_is_null = $('#<?php 
            echo $uniqid;
            ?>
___is_null');
                    var $input = $('#<?php 
            echo $uniqid;
            ?>
_radio_box').find('input[type="radio"]');

                    $input.on('change', function () {
                        $input_is_null.prop('checked', false);
                    });

                    $input_is_null.on('change', function () {
                        if ($(this).is(':checked')) {
                            $input.prop('checked', false);
                        }
                    });
                })();
            </script>
            <?php 
            $html .= ob_get_clean();
        }
        $html .= '</div>';
        return $html;
    }
Ejemplo n.º 17
0
 /**
  * table_id - это идентификатор таблицы на странице, к которому привязываются все данные: имена полей формы и т.п.
  * @param $model_class_name
  * @param $create_form_html
  * @param $column_obj_arr
  * @param array $filters_arr
  * @param string $order_by
  * @return string
  */
 public static function html($model_class_name, $create_form_html, $column_obj_arr, $filters_arr = [], $order_by = '', $table_id = '', $filters_position = self::FILTERS_POSITION_NONE)
 {
     // TODO: придумать способ автогенерации table_id, который был бы уникальным, но при этом один и тот же когда одну таблицу запрашиваешь несколько раз
     self::executeOperations();
     //
     // вывод таблицы
     //
     $table_container_element_id = uniqid('tableContainer_');
     if ($table_id) {
         $table_container_element_id = $table_id;
     }
     // оборачиваем в отдельный div для выдачи только таблицы аяксом - иначе корневой элемент документа не будет доступен в jquery селекторах
     $html = HTML::div($table_container_element_id, '', function () use($model_class_name, $create_form_html, $column_obj_arr, $filters_arr, $order_by, $table_id, $filters_position) {
         echo '<div class="row">';
         if ($filters_position == self::FILTERS_POSITION_LEFT) {
             echo '<div class="col-sm-4">';
             echo self::filtersHtml($table_id, $filters_arr);
             echo '</div>';
         }
         $col_sm_class = '12';
         if ($filters_position == self::FILTERS_POSITION_LEFT || $filters_position == self::FILTERS_POSITION_RIGHT) {
             $col_sm_class = '8';
         }
         echo '<div class="col-sm-' . $col_sm_class . '">';
         echo self::toolbarHtml($table_id, $create_form_html, $filters_arr);
         if ($filters_position == self::FILTERS_POSITION_TOP) {
             echo self::filtersHtml($table_id, $filters_arr);
         }
         if ($filters_position == self::FILTERS_POSITION_INLINE) {
             echo self::filtersHtmlInline($table_id, $filters_arr);
         }
         echo '<table class="table table-hover">';
         /** @var InterfaceCRUDTableColumn $column_obj */
         echo '<thead><tr>';
         foreach ($column_obj_arr as $column_obj) {
             Assert::assert($column_obj instanceof InterfaceCRUDTableColumn);
             echo '<th>' . Sanitize::sanitizeTagContent($column_obj->getTitle()) . '</th>';
         }
         echo '</tr></thead>';
         echo '<tbody>';
         $objs_ids_arr = CRUDInternalTableObjectsSelector::getObjIdsArrForClassName($table_id, $model_class_name, $filters_arr, $order_by);
         foreach ($objs_ids_arr as $obj_id) {
             $obj_obj = CRUDObjectLoader::createAndLoadObject($model_class_name, $obj_id);
             /** @var InterfaceCRUDTableColumn $column_obj */
             echo '<tr>';
             foreach ($column_obj_arr as $column_obj) {
                 Assert::assert($column_obj instanceof InterfaceCRUDTableColumn);
                 /** @var InterfaceCRUDTableWidget $widget_obj */
                 $widget_obj = $column_obj->getWidgetObj();
                 Assert::assert($widget_obj);
                 Assert::assert($widget_obj instanceof InterfaceCRUDTableWidget);
                 $col_width_attr = '';
                 if ($widget_obj instanceof CRUDTableWidgetDelete) {
                     $col_width_attr = ' width="1px" ';
                 }
                 if ($widget_obj instanceof CRUDTableWidgetWeight) {
                     $col_width_attr = ' width="1px" ';
                 }
                 echo '<td ' . $col_width_attr . ' style="word-break: break-all;">';
                 echo $widget_obj->html($obj_obj);
                 echo '</td>';
             }
             echo '</tr>';
         }
         echo '</tbody>';
         echo '</table>';
         echo Pager::renderPager($table_id, count($objs_ids_arr));
         echo '</div>';
         if ($filters_position == self::FILTERS_POSITION_RIGHT) {
             echo '<div class="col-sm-4">';
             echo self::filtersHtml($table_id, $filters_arr);
             echo '</div>';
         }
         echo '</div>';
     });
     // Загрузка скриптов
     $html .= CRUDTableScript::getHtml($table_container_element_id, Url::getCurrentUrlNoGetForm());
     return $html;
 }
 /**
  * Возвращает пару из sql-условия и массива значений плейсхолдеров. Массив значений может быть пустой если плейсхолдеры не нужны.
  * @return array
  */
 public function sqlConditionAndPlaceholderValue()
 {
     if (!$this->isEnabled()) {
         return ['', []];
     }
     $value = $this->getValue();
     $sanitized_column_name = Sanitize::sanitizeSqlColumnName($this->getFieldName());
     if (is_null($value)) {
         return [' ' . $sanitized_column_name . ' is null ', []];
     }
     return [' ' . $sanitized_column_name . ' = ? ', [$value]];
 }
Ejemplo n.º 19
0
    public function html($obj)
    {
        $field_name = $this->getFieldName();
        $field_value = CRUDFieldsAccess::getObjectFieldValue($obj, $field_name);
        $is_required_str = '';
        if ($this->is_required) {
            $is_required_str = ' required ';
        }
        $uniqid = uniqid('CRUDFormWidgetInput_');
        $input_cols = $this->getShowNullCheckbox() ? '10' : '12';
        $html = '';
        $html .= '<div class="row">';
        $html .= '<div class="col-sm-' . $input_cols . '">';
        $html .= '<input id="' . $uniqid . '_input" name="' . Sanitize::sanitizeAttrValue($field_name) . '" ' . $is_required_str . ' class="form-control" value="' . Sanitize::sanitizeAttrValue($field_value) . '"/>';
        $html .= '</div>';
        if ($this->getShowNullCheckbox()) {
            $is_null_checked = '';
            if (is_null($field_value)) {
                $is_null_checked = ' checked ';
            }
            ob_start();
            ?>
            <div class="col-sm-2">
                <label class="form-control-static">
                    <input id="<?php 
            echo $uniqid;
            ?>
___is_null" type="checkbox" value="1" name="<?php 
            echo Sanitize::sanitizeAttrValue($field_name);
            ?>
___is_null" <?php 
            echo $is_null_checked;
            ?>
> NULL
                </label>
            </div>
            <script>
                (function () {
                    var $input_is_null = $('#<?php 
            echo $uniqid;
            ?>
___is_null');
                    var $input = $('#<?php 
            echo $uniqid;
            ?>
_input');

                    $input.on('change keydown', function () {
                        $input_is_null.prop('checked', false);
                    });

                    $input_is_null.on('change', function () {
                        if ($(this).is(':checked')) {
                            $input.val('');
                        }
                    });
                })();
            </script>
            <?php 
            $html .= ob_get_clean();
        }
        $html .= '</div>';
        return $html;
    }
Ejemplo n.º 20
0
 /**
  * ид объекта может быть пустым - тогда при сохранении формы создаст новый объект
  * @param $obj
  * @param $element_obj_arr
  * @param string $url_to_redirect_after_save
  * @param array $redirect_get_params_arr
  * @return string html-код формы редактирования
  * @throws \Exception
  */
 public static function html($obj, $element_obj_arr, $url_to_redirect_after_save = '', $redirect_get_params_arr = [], $form_id = '', $operation_code = self::OPERATION_SAVE_EDITOR_FORM, $hide_submit_button = false)
 {
     self::executeOperations($url_to_redirect_after_save, $redirect_get_params_arr);
     $form_element_id = 'formElem_' . uniqid();
     if ($form_id) {
         $form_element_id = $form_id;
     }
     $html = '';
     $html .= '<form id="' . $form_element_id . '" class="form-horizontal" role="form" method="post" action="' . Sanitize::sanitizeUrl(\OLOG\Url::getCurrentUrl()) . '">';
     $html .= Operations::operationCodeHiddenField($operation_code);
     $html .= '<input type="hidden" name="' . self::FIELD_CLASS_NAME . '" value="' . Sanitize::sanitizeAttrValue(get_class($obj)) . '">';
     $html .= '<input type="hidden" name="' . self::FIELD_OBJECT_ID . '" value="' . Sanitize::sanitizeAttrValue(CRUDFieldsAccess::getObjId($obj)) . '">';
     /** @var InterfaceCRUDFormRow $element_obj */
     foreach ($element_obj_arr as $element_obj) {
         Assert::assert($element_obj instanceof InterfaceCRUDFormRow);
         $html .= $element_obj->html($obj);
     }
     $html .= '<div class="row">';
     $html .= '<div class="col-sm-8 col-sm-offset-4">';
     if (!$hide_submit_button) {
         $html .= '<button style="width: 100%" type="submit" class="btn btn-primary">Сохранить</button>';
     }
     $html .= '</div>';
     $html .= '</div>';
     $html .= '</form>';
     // Загрузка скриптов
     $html .= CRUDFormScript::getHtml($form_element_id);
     return $html;
 }
Ejemplo n.º 21
0
 /**
  * Returns sanitized content.
  * @param $obj
  * @return mixed
  */
 public function html($obj)
 {
     $timestamp = CRUDCompiler::compile($this->getTimestamp(), ['this' => $obj]);
     $date = date($this->getFormat(), $timestamp);
     return Sanitize::sanitizeTagContent($date);
 }
Ejemplo n.º 22
0
    public static function render($content_html, $action_obj = null)
    {
        $page_toolbar_html = '';
        // запрашиваем до начала вывода на страницу, потому что там может редирект или какая-то еще работа с хидерами
        if ($action_obj) {
            if ($action_obj instanceof \OLOG\Layouts\InterfacePageToolbarHtml) {
                $page_toolbar_html = $action_obj->pageToolbarHtml();
            }
        }
        ?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>

	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
	      integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

	<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"
	        integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS"
	        crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
	<?php 
        //$application_title = BTConfig::getApplicationTitle();
        $application_title = 'Home';
        $menu_items_arr = [];
        if ($action_obj instanceof InterfaceMenu) {
            $menu_items_arr = $action_obj::menuArr();
        }
        ?>
	<nav class="navbar navbar-inverse">
		<div class="container-fluid">
			<!-- Brand and toggle get grouped for better mobile display -->
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
				        data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
					<span class="sr-only">Toggle navigation</span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
				</button>
				<a class="navbar-brand" href="/"><?php 
        echo $application_title;
        ?>
</a>
			</div>

			<!-- Collect the nav links, forms, and other content for toggling -->
			<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
				<ul class="nav navbar-nav">
					<?php 
        foreach ($menu_items_arr as $menu_item_obj) {
            \OLOG\Assert::assert($menu_item_obj instanceof \OLOG\Layouts\MenuItem);
            $children_arr = $menu_item_obj->getChildrenArr();
            $href = 'href="#"';
            if ($menu_item_obj->getUrl()) {
                $href = 'href="' . Sanitize::sanitizeUrl($menu_item_obj->getUrl()) . '"';
            }
            $icon = '';
            if ($menu_item_obj->getIconClassesStr()) {
                $icon = '<i class="' . $menu_item_obj->getIconClassesStr() . '"></i> ';
            }
            if (count($children_arr)) {
                ?>
							<li class="dropdown">
								<a <?php 
                echo $href;
                ?>
 class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
									<?php 
                echo $icon . Sanitize::sanitizeTagContent($menu_item_obj->getText());
                ?>
 <span class="caret"></span>
								</a>
								<ul class="dropdown-menu">
									<?php 
                /** @var  $child_menu_item_obj \OLOG\Layouts\MenuItem */
                foreach ($children_arr as $child_menu_item_obj) {
                    \OLOG\Assert::assert($child_menu_item_obj instanceof \OLOG\Layouts\MenuItem);
                    $children_href = '';
                    if ($child_menu_item_obj->getUrl()) {
                        $children_href = 'href="' . Sanitize::sanitizeUrl($child_menu_item_obj->getUrl()) . '"';
                    }
                    $children_icon = '';
                    if ($child_menu_item_obj->getIconClassesStr()) {
                        $children_icon = '<i class="' . $child_menu_item_obj->getIconClassesStr() . '"></i> ';
                    }
                    ?>
										<li>
											<a <?php 
                    echo $children_href;
                    ?>
><?php 
                    echo $children_icon . Sanitize::sanitizeTagContent($child_menu_item_obj->getText());
                    ?>
</a>
										</li>
										<?php 
                }
                ?>
								</ul>
							</li>
							<?php 
            } else {
                ?>
							<li>
								<a <?php 
                echo $href;
                ?>
><?php 
                echo $icon . Sanitize::sanitizeTagContent($menu_item_obj->getText());
                ?>
</a>
							</li>
							<?php 
            }
        }
        ?>
				</ul>
			</div><!-- /.navbar-collapse -->
		</div><!-- /.container-fluid -->
	</nav>
	<?php 
        $h1_str = '';
        //$breadcrumbs_arr = ConfWrapper::getOptionalValue(\OLOG\BT\BTConstants::MODULE_NAME . '.' . \OLOG\BT\BTConstants::BREADCRUMBS_PREFIX_ARR, []);
        //$breadcrumbs_arr = BTConfig::getBreadcrumbsPrefixArr();
        $breadcrumbs_arr = [];
        if ($action_obj) {
            /*
            if ($action_obj instanceof InterfaceBreadcrumbs) {
            	$breadcrumbs_arr = array_merge($breadcrumbs_arr, $action_obj->currentBreadcrumbsArr());
            }
            */
            if ($action_obj instanceof \OLOG\Layouts\InterfaceTopActionObj) {
                $top_action_obj = $action_obj->topActionObj();
                $extra_breadcrumbs_arr = [];
                while ($top_action_obj) {
                    $top_action_title = '#NO_TITLE#';
                    if ($top_action_obj instanceof \OLOG\Layouts\InterfacePageTitle) {
                        $top_action_title = $top_action_obj->pageTitle();
                    }
                    $top_action_url = '#NO_URL#';
                    if ($top_action_obj instanceof InterfaceAction) {
                        $top_action_url = $top_action_obj->url();
                    }
                    array_unshift($extra_breadcrumbs_arr, HTML::a($top_action_url, $top_action_title));
                    $top_action_obj = null;
                    if ($top_action_obj instanceof \OLOG\Layouts\InterfaceTopActionObj) {
                        $top_action_obj = $top_action_obj->topActionObj();
                    }
                }
                $breadcrumbs_arr = array_merge($breadcrumbs_arr, $extra_breadcrumbs_arr);
            }
            if ($action_obj instanceof \OLOG\Layouts\InterfacePageTitle) {
                $h1_str = $action_obj->pageTitle();
            }
        }
        if (!empty($breadcrumbs_arr)) {
            echo BT::breadcrumbs($breadcrumbs_arr);
        }
        ?>
	<div class="page-header">
		<h1>
			<?php 
        echo $h1_str;
        ?>
			<?php 
        if ($page_toolbar_html != '') {
            echo '<span>' . $page_toolbar_html . '</span>';
        }
        ?>
		</h1>
	</div>
	<?php 
        echo $content_html;
        ?>
</div>
</body>
</html>
<?php 
    }
Ejemplo n.º 23
0
    public function html($obj)
    {
        static $CRUDFormWidgetDateTime_include_script;
        $field_name = $this->getFieldName();
        $field_value = CRUDFieldsAccess::getObjectFieldValue($obj, $field_name);
        /* Нужно изменить на нах CDN */
        $script = '';
        if (!isset($CRUDFormWidgetDateTime_include_script)) {
            $script = '
								<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.2/moment.min.js"></script>
								<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.2/locale/ru.js"></script>
				<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.43/css/bootstrap-datetimepicker.min.css">
								<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.43/js/bootstrap-datetimepicker.min.js"></script>
			';
            $CRUDFormWidgetDateTime_include_script = false;
        }
        $is_required_str = '';
        if ($this->is_required) {
            $is_required_str = ' required ';
        }
        $field_value_attr = '';
        if ($field_value) {
            $field_value_attr = date('d-m-Y H:i:s', strtotime($field_value));
        }
        $uniqid = uniqid('CRUDFormWidgetDateTime_');
        $input_cols = $this->getShowNullCheckbox() ? '10' : '12';
        $html = '';
        $html .= '<div class="row">';
        $html .= '<div class="col-sm-' . $input_cols . '">';
        ob_start();
        ?>
		<input type="hidden" id="<?php 
        echo $uniqid;
        ?>
_input" name="<?php 
        echo Sanitize::sanitizeAttrValue($field_name);
        ?>
" value="<?php 
        echo Sanitize::sanitizeTagContent($field_value);
        ?>
" data-field="<?php 
        echo $uniqid;
        ?>
_date" <?php 
        echo $is_required_str;
        ?>
>
		<div class="input-group date" id="<?php 
        echo $uniqid;
        ?>
">
			<input id="<?php 
        echo $uniqid;
        ?>
_date" type="text" class="form-control" value="<?php 
        echo $field_value_attr;
        ?>
">
			<span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
		</div>
		<script>
			$("#<?php 
        echo $uniqid;
        ?>
").datetimepicker({
				format: "DD-MM-YYYY HH:mm:ss",
				sideBySide: true,
				showTodayButton: true
			}).on("dp.change", function (obj) {
				if (obj.date) {
					$("#<?php 
        echo $uniqid;
        ?>
_input").val(obj.date.format("YYYY-MM-DD HH:mm:ss")).trigger('change');
				} else {
					$("#<?php 
        echo $uniqid;
        ?>
_input").val('').trigger('change');
				}
			});
		</script>
		<?php 
        $html .= ob_get_clean();
        $html .= '</div>';
        if ($this->getShowNullCheckbox()) {
            $is_null_checked = '';
            if (is_null($field_value)) {
                $is_null_checked = ' checked ';
            }
            ob_start();
            ?>
			<div class="col-sm-2">
				<label class="form-control-static">
					<input id="<?php 
            echo $uniqid;
            ?>
___is_null" type="checkbox" value="1" name="<?php 
            echo Sanitize::sanitizeAttrValue($field_name);
            ?>
___is_null" <?php 
            echo $is_null_checked;
            ?>
> NULL
				</label>
			</div>
			<script>
				(function () {
					var $input_is_null = $('#<?php 
            echo $uniqid;
            ?>
___is_null');

					$("#<?php 
            echo $uniqid;
            ?>
_input").on('change', function () {
						$input_is_null.prop('checked',false);
					});

					$input_is_null.on('change', function () {
						if ($(this).is(':checked')) {
							$('#<?php 
            echo $uniqid;
            ?>
').data("DateTimePicker").clear();
							$('#<?php 
            echo $uniqid;
            ?>
_input').val('');
						}
					});
				})();
			</script>
			<?php 
            $html .= ob_get_clean();
        }
        $html .= '</div>';
        return $script . $html;
    }
Ejemplo n.º 24
0
 /**
  * Returns sanitized content.
  * @param $obj
  * @return mixed
  */
 public function html($obj)
 {
     $html = CRUDCompiler::compile($this->getText(), ['this' => $obj]);
     return Sanitize::sanitizeTagContent($html);
 }
Ejemplo n.º 25
0
Archivo: BT.php Proyecto: o-log/php-bt
 public static function tabHtml($text, $match_url, $link_url, $target = '')
 {
     $classes = '';
     // TODO: код взят из Router::match3() - использовать общую реализацию?
     $url_regexp = '@^' . $match_url . '$@';
     $matches_arr = array();
     $current_url = self::uri_no_getform();
     // TODO: use common request reader
     if (preg_match($url_regexp, $current_url, $matches_arr)) {
         $classes .= ' active ';
     }
     if ($link_url == '') {
         $classes .= ' disabled ';
     }
     $html = '';
     $html .= '<li role="presentation" class="' . Sanitize::sanitizeAttrValue($classes) . '">';
     $html .= BT::a($link_url, $text, '', $target);
     $html .= '</li>';
     return $html;
 }
Ejemplo n.º 26
0
    public function htmlForValue($field_value, $input_name = null)
    {
        $field_name = $this->getFieldName();
        if (is_null($input_name)) {
            $input_name = $field_name;
        }
        $referenced_class_name = $this->getReferencedClassName();
        $referenced_class_title_field = $this->getReferencedClassTitleField();
        $referenced_obj_title = '';
        $disabled_btn_link = 'disabled';
        $is_null_value = '';
        if (is_null($field_value)) {
            $is_null_value = "1";
        }
        if (!is_null($field_value)) {
            $referenced_obj = CRUDObjectLoader::createAndLoadObject($referenced_class_name, $field_value);
            $referenced_obj_title = CRUDFieldsAccess::getObjectFieldValue($referenced_obj, $referenced_class_title_field);
            $disabled_btn_link = '';
        }
        $is_required_str = '';
        if ($this->is_required) {
            $is_required_str = ' required ';
        }
        $html = '';
        $html .= Preloader::preloaderJsHtml();
        $select_element_id = 'js_select_' . rand(1, 999999);
        $choose_form_element_id = 'collapse_' . rand(1, 999999);
        $html .= '<input type="hidden" id="' . Sanitize::sanitizeAttrValue($select_element_id) . '" name="' . Sanitize::sanitizeAttrValue($input_name) . '" value="' . $field_value . '" data-field="' . Sanitize::sanitizeAttrValue($select_element_id) . '_text" ' . $is_required_str . '/>';
        $html .= '<input type="hidden" id="' . Sanitize::sanitizeAttrValue($select_element_id) . '_is_null" name="' . Sanitize::sanitizeAttrValue($input_name) . '___is_null" value="' . $is_null_value . '"/>';
        $html .= '<div class="input-group">';
        if ($this->getAjaxActionUrl()) {
            $html .= '<span class="input-group-btn">';
            $html .= '<button type="button" class="btn btn-default" data-toggle="modal" data-target="#' . $choose_form_element_id . '"><span class="glyphicon glyphicon-folder-open"></span></button>';
            $html .= '<button type="button" id="' . Sanitize::sanitizeAttrValue($select_element_id) . '_btn_is_null" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span></button>';
            $html .= '</span>';
        }
        $html .= '<div class="form-control" id="' . Sanitize::sanitizeAttrValue($select_element_id) . '_text">' . $referenced_obj_title . '</div>';
        if ($this->getEditorUrl()) {
            $html .= '<span class="input-group-btn">';
            $html .= '<button ' . $disabled_btn_link . ' type="button" id="' . Sanitize::sanitizeAttrValue($select_element_id) . '_btn_link" class="btn btn-default">Перейти</button>';
            $html .= '</span>';
        }
        $html .= '</div>';
        $html .= BT::modal($choose_form_element_id, 'Выбрать');
        ob_start();
        ?>

        <script>
            $('#<?php 
        echo $choose_form_element_id;
        ?>
').on('hidden.bs.modal', function () {
	            $('#<?php 
        echo $choose_form_element_id;
        ?>
 .modal-body').html('');
            });

            $('#<?php 
        echo $choose_form_element_id;
        ?>
').on('shown.bs.modal', function (e) {
	            OLOG.preloader.show();
                $.ajax({
                    url: "<?php 
        echo $this->getAjaxActionUrl();
        ?>
"
                }).success(function(received_html) {
                    $('#<?php 
        echo $choose_form_element_id;
        ?>
 .modal-body').html(received_html);
	                OLOG.preloader.hide();
                });
            });

            $('#<?php 
        echo $choose_form_element_id;
        ?>
').on('click', '.js-ajax-form-select', function (e) {
            	e.preventDefault();
                var select_id = $(this).data('id');
                var select_title = $(this).data('title');
				$('#<?php 
        echo $choose_form_element_id;
        ?>
').modal('hide');
				$('#<?php 
        echo $select_element_id;
        ?>
_text').text(select_title);
                $('#<?php 
        echo $select_element_id;
        ?>
_btn_link').attr('disabled', false);
				$('#<?php 
        echo $select_element_id;
        ?>
').val(select_id).trigger('change');
				$('#<?php 
        echo $select_element_id;
        ?>
_is_null').val('');
			});

			$('#<?php 
        echo $select_element_id;
        ?>
_btn_is_null').on('click', function (e) {
				e.preventDefault();
				$('#<?php 
        echo $select_element_id;
        ?>
_text').text('');
                $('#<?php 
        echo $select_element_id;
        ?>
_btn_link').attr('disabled', true);
				$('#<?php 
        echo $select_element_id;
        ?>
').val('').trigger('change');
				$('#<?php 
        echo $select_element_id;
        ?>
_is_null').val(1);
			});

            $('#<?php 
        echo $select_element_id;
        ?>
_btn_link').on('click', function (e) {
                var url = '<?php 
        echo $this->getEditorUrl();
        ?>
';
                var id = $('#<?php 
        echo $select_element_id;
        ?>
').val();
                url = url.replace('REFERENCED_ID', id);

                window.location = url;
            });
        </script>

        <?php 
        $html .= ob_get_clean();
        return $html;
    }