Beispiel #1
0
 public function action()
 {
     Exits::exit403If(!Operator::currentOperatorHasAnyOfPermissions([Permissions::PERMISSION_PHPAUTH_MANAGE_OPERATORS]));
     $operator_id = $this->operator_id;
     $operator_obj = Operator::factory($operator_id);
     $html = '<div class="col-md-6">';
     $html .= '<h2>Параметры</h2>';
     $html .= CRUDForm::html($operator_obj, [new CRUDFormRow('title', new CRUDFormWidgetInput('title')), new CRUDFormRow('описание', new CRUDFormWidgetTextarea('description')), new CRUDFormRow('User id', new CRUDFormWidgetReferenceAjax('user_id', User::class, 'login', (new UsersListAjaxAction())->url(), (new UserEditAction('REFERENCED_ID'))->url()))]);
     $new_operator_permission_obj = new OperatorPermission();
     $new_operator_permission_obj->setOperatorId($operator_id);
     $html .= '</div><div class="col-md-6">';
     if (Operator::currentOperatorHasAnyOfPermissions([Permissions::PERMISSION_PHPAUTH_MANAGE_OPERATORS])) {
         $html .= '<h2>Назначенные разрешения</h2>';
         $html .= HTML::div('', '', function () use($operator_id) {
             $new_permissiontouser_obj = new OperatorPermission();
             $new_permissiontouser_obj->setOperatorId($operator_id);
             echo CRUDTable::html(OperatorPermission::class, '', [new \OLOG\CRUD\CRUDTableColumn('Разрешение', new \OLOG\CRUD\CRUDTableWidgetText('{' . Permission::class . '.{this->permission_id}->title}')), new \OLOG\CRUD\CRUDTableColumn('Удалить', new \OLOG\CRUD\CRUDTableWidgetDelete())], [new CRUDTableFilterEqualInvisible('operator_id', $operator_id)], '');
             echo CallapsibleWidget::buttonAndCollapse('Показать все неназначенные разрешения', function () use($operator_id) {
                 $html = CRUDTable::html(Permission::class, '', [new CRUDTableColumn('Разрешение', new CRUDTableWidgetTextWithLink('{this->title}', (new PermissionAddToOperatorAction($operator_id, '{this->id}'))->url())), new CRUDTableColumn('', new CRUDTableWidgetTextWithLink('Добавить оператору', (new PermissionAddToOperatorAction($operator_id, '{this->id}'))->url(), 'btn btn-default btn-xs'))], [new CRUDTableFilterNotInInvisible('id', OperatorPermission::getPermissionIdsArrForOperatorId($operator_id))], 'id', '79687tg8976rt87');
                 return $html;
             });
         });
     }
     $html .= '</div>';
     AdminLayoutSelector::render($html, $this);
 }
    public function getHtml()
    {
        $html = HTML::div('js-filter', '', function () {
            $input_name = $this->getFilterIniqId();
            /**
             * отдельное поле, наличие которого сообщает что фильтр присутствует в форме
             * (все другие поля могут отсутствовать когда фильтр например запрещен и т.п.)
             */
            echo '<input type="hidden" name="' . $this->filterIsPassedInputName() . '" value="1">';
            echo '<input type="hidden" name="' . $this->enabledCheckboxInputName() . '" value="' . ($this->isEnabled() ? '1' : '') . '">';
            echo '<span onclick="f' . $input_name . '_changeFiltres(this);" class="btn btn-xs btn-default ' . ($this->isEnabled() ? '' : 'active') . '">' . $this->getBtnAllText() . '</span>';
            echo '<input type="hidden" name="' . $input_name . '" value="' . ($this->isEnabled() ? $this->getValue() : '') . '">';
            $options_arr = $this->getOptionsArr();
            foreach ($options_arr as $value => $title) {
                echo '<span data-value="' . $value . '" data-enabled="1" onclick="f' . $input_name . '_changeFiltres(this);" class="btn btn-xs btn-default ' . ($this->isEnabled() && $this->getValue() == $value ? 'active' : '') . '">' . $title . '</span>';
            }
            if ($this->getShowNullCheckbox()) {
                echo '<input type="hidden" name="' . $this->nullCheckboxInputName() . '" value="' . (is_null($this->getValue()) && $this->isEnabled() ? '1' : '') . '">';
                echo '<span data-isnull="1" data-enabled="1" onclick="f' . $input_name . '_changeFiltres(this);" class="btn btn-xs btn-default ' . (is_null($this->getValue()) && $this->isEnabled() ? 'active' : '') . '">Не указано</span>';
            }
        });
        $input_name = $this->getFilterIniqId();
        ob_start();
        ?>
        <script>
        function f<?php 
        echo $input_name;
        ?>
_changeFiltres(select_element){
	        var $this = $(select_element);
	        var $form = $this.closest('form');
	        var $filter = $this.closest('.js-filter');

	        $filter.find('.btn').removeClass('active');
	        $this.addClass('active');

	        var enabled = $this.data('enabled') || '';
	        var value = $this.data('value') || '';
	        var isnull = $this.data('isnull') || '';

	        $filter.find('[name="<?php 
        echo $this->enabledCheckboxInputName();
        ?>
"]').val(enabled);
	        $filter.find('[name="<?php 
        echo $input_name;
        ?>
"]').val(value);
	        $filter.find('[name="<?php 
        echo $this->nullCheckboxInputName();
        ?>
"]').val(isnull);

	        $form.submit();
        }
        </script>
		<?php 
        $script = ob_get_clean();
        return $html . $script;
    }
 public function html($obj)
 {
     $url = CRUDCompiler::compile($this->getLink(), ['this' => $obj]);
     $html = CRUDCompiler::compile($this->getHtml(), ['this' => $obj]);
     if (trim($html) == '') {
         $html = '#EMPTY#';
     }
     return HTML::tag('a', ['href' => $url, 'class' => $this->getClassesStr()], $html);
 }
Beispiel #4
0
 public function action()
 {
     Exits::exit403If(!Operator::currentOperatorHasAnyOfPermissions([Permissions::PERMISSION_PHPAUTH_MANAGE_OPERATORS, Permissions::PERMISSION_PHPAUTH_MANAGE_USERS]));
     $html = '';
     $html .= '<div>' . HTML::a((new PermissionsListAction())->url(), 'Разрешения') . '</div>';
     $html .= '<div>' . HTML::a((new UsersListAction())->url(), 'Пользователи') . '</div>';
     $html .= '<div>' . HTML::a((new GroupsListAction())->url(), 'Группы') . '</div>';
     $html .= '<div>' . HTML::a((new OperatorsListAction())->url(), 'Операторы') . '</div>';
     AdminLayoutSelector::render($html, $this);
 }
Beispiel #5
0
 public function action()
 {
     Exits::exit403If(!Operator::currentOperatorHasAnyOfPermissions([Permissions::PERMISSION_PHPAUTH_MANAGE_USERS]));
     $user_id = $this->user_id;
     $user_obj = User::factory($user_id);
     Exits::exit403If(!OwnerCheck::currentUserOwnsObj($user_obj));
     Operations::matchOperation(self::OPERATION_SET_PASSWORD, function () use($user_id) {
         $new_password = POSTAccess::getOptionalPostValue(self::FIELD_NAME_PASSWORD);
         $new_password_hash = password_hash($new_password, PASSWORD_BCRYPT);
         $user_obj = User::factory($user_id);
         $user_obj->setPasswordHash($new_password_hash);
         $user_obj->save();
     });
     $html = '';
     $html .= '<div class="row"><div class="col-md-6">';
     $html .= self::commonParamsForm($user_id);
     $html .= self::passwordForm();
     $html .= self::userOperatorsTable($user_id);
     $html .= self::adminParamsForm($user_id);
     $html .= '</div><div class="col-md-6">';
     if (Operator::currentOperatorHasAnyOfPermissions([Permissions::PERMISSION_PHPAUTH_MANAGE_USERS_PERMISSIONS])) {
         $html .= '<h2>Разрешения</h2>';
         $html .= HTML::div('', '', function () use($user_id) {
             $new_permissiontouser_obj = new PermissionToUser();
             $new_permissiontouser_obj->setUserId($user_id);
             echo CRUDTable::html(PermissionToUser::class, '', [new \OLOG\CRUD\CRUDTableColumn('Разрешение', new \OLOG\CRUD\CRUDTableWidgetText('{' . Permission::class . '.{this->permission_id}->title}')), new \OLOG\CRUD\CRUDTableColumn('Удалить', new \OLOG\CRUD\CRUDTableWidgetDelete())], [new CRUDTableFilterEqualInvisible('user_id', $user_id)], '');
             echo CallapsibleWidget::buttonAndCollapse('Показать все неназначенные разрешения', function () use($user_id) {
                 $html = CRUDTable::html(Permission::class, '', [new CRUDTableColumn('Разрешение', new CRUDTableWidgetTextWithLink('{this->title}', (new PermissionAddToUserAction($user_id, '{this->id}'))->url())), new CRUDTableColumn('', new CRUDTableWidgetTextWithLink('Добавить пользователю', (new PermissionAddToUserAction($user_id, '{this->id}'))->url(), 'btn btn-default btn-xs'))], [new CRUDTableFilterNotInInvisible('id', PermissionToUser::getPermissionIdsArrForUserId($user_id))], 'id', '79687tg8976rt87');
                 return $html;
             });
         });
     }
     $html .= self::userInGroupsTable($user_id);
     $html .= '</div></div>';
     AdminLayoutSelector::render($html, $this);
 }
Beispiel #6
0
 protected static function filtersHtmlInline($table_index_on_page, $filters_arr)
 {
     if (empty($filters_arr)) {
         return '';
     }
     $html = HTML::div('filters-inline', '', function () use($table_index_on_page, $filters_arr) {
         echo '<form class="filters-form">';
         foreach ($filters_arr as $filter_obj) {
             if ($filter_obj instanceof InterfaceCRUDTableFilter2) {
                 echo '<div style="display: inline-block;margin-right: 10px;">';
                 if ($filter_obj->getTitle()) {
                     echo '<span style="display: inline-block;margin-right: 5px;">' . $filter_obj->getTitle() . '</span>';
                 }
                 echo '<span style="display: inline-block;">' . $filter_obj->getHtml() . '</span>';
                 echo '</div>';
             } elseif ($filter_obj instanceof InterfaceCRUDTableFilterInvisible) {
                 // do nothing with invisible filters
             } else {
                 throw new \Exception('filter doesnt implement interface ...');
             }
         }
         echo '</form>';
     });
     return $html;
 }
Beispiel #7
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 
    }