示例#1
0
         break;
     }
     $a->buttons = false;
     $a->cancel_button_back = true;
     $group = $Group->get($rc[3]);
     $Page->title($L->deletion_of_group($group['title']));
     $a->content(h::{'p.lead.cs-center'}($L->sure_delete_group($group['title'])) . h::{'input[type=hidden]'}(['name' => 'id', 'value' => $rc[3]]) . h::{'button[type=submit]'}($L->yes));
     $Page->warning($L->changing_settings_warning);
     break;
 case 'permissions':
     if (!isset($rc[3])) {
         break;
     }
     $a->apply_button = false;
     $a->cancel_button_back = true;
     $permissions = Permission::instance()->get_all();
     $group_permissions = $Group->get_permissions($rc[3]);
     $tabs = [];
     $tabs_content = '';
     $blocks = [];
     foreach ($Config->components['blocks'] as $block) {
         $blocks[$block['index']] = $block['title'];
     }
     unset($block);
     foreach ($permissions as $group => $list) {
         $tabs[] = h::a($group, ['href' => '#permissions_group_' . strtr($group, '/', '_')]);
         $content = [];
         foreach ($list as $label => $id) {
             $content[] = h::th($group == 'Block' ? Text::instance()->process($Config->module('System')->db('texts'), $blocks[$label]) : $label) . h::{'td input[type=radio]'}(['name' => "permission[{$id}]", 'checked' => isset($group_permissions[$id]) ? $group_permissions[$id] : -1, 'value' => [-1, 0, 1], 'in' => [$L->not_specified, $L->deny, $L->allow]]);
         }
         if (count($list) % 2) {
示例#2
0
/**
 * @package		CleverStyle CMS
 * @subpackage	System module
 * @category	modules
 * @author		Nazar Mokrynskyi <*****@*****.**>
 * @copyright	Copyright (c) 2011-2014, Nazar Mokrynskyi
 * @license		MIT License, see license.txt
 */
namespace cs;

use h;
$Config = Config::instance();
$L = Language::instance();
$Page = Page::instance();
$Permission = Permission::instance();
$a = Index::instance();
$rc = $Config->route;
if (isset($rc[2])) {
    switch ($rc[2]) {
        case 'add':
            $a->apply_button = false;
            $a->cancel_button_back = true;
            $Page->title($L->adding_permission);
            $a->content(h::{'p.lead.cs-center'}($L->adding_permission) . h::{'table.cs-table-borderless.cs-center-all'}(h::{'thead tr th'}([$L->group, $L->label]) . h::{'tbody tr td'}([h::{'input[name=permission[group]]'}(), h::{'input[name=permission[label]]'}()])));
            break;
        case 'edit':
            if (!isset($rc[3])) {
                break;
            }
            $a->apply_button = false;
示例#3
0
     $block =& $Config->components['blocks'][$rc[3]];
     $Page->title($L->editing_a_block(get_block_title($rc[3])));
     $a->content(h::{'p.lead.cs-center'}($L->editing_a_block(get_block_title($rc[3]))) . h::{'table.cs-table-borderless.cs-center-all tr'}(\cs\modules\System\form_rows_to_cols([array_map(function ($in) {
         return h::{'th info'}($in);
     }, ['block_title', 'block_active', 'block_template', 'block_start', 'block_expire']), array_map(function ($in) {
         return h::td($in);
     }, [h::input(['name' => 'block[title]', 'value' => get_block_title($rc[3])]), h::{'div input[type=radio]'}(['name' => 'block[active]', 'checked' => $block['active'], 'value' => [1, 0], 'in' => [$L->yes, $L->no]]), h::select(['in' => _mb_substr(get_files_list(TEMPLATES . '/blocks', '/^block\\..*?\\.(php|html)$/i', 'f'), 6)], ['name' => 'block[template]', 'selected' => $block['template'], 'size' => 5]), h::{'input[type=datetime-local]'}(['name' => 'block[start]', 'value' => date('Y-m-d\\TH:i', $block['start'] ?: TIME)]), h::{'input[type=radio]'}(['name' => 'block[expire][state]', 'checked' => $block['expire'] != 0, 'value' => [0, 1], 'in' => [$L->never, $L->as_specified]]) . h::br(2) . h::{'input[type=datetime-local]'}(['name' => 'block[expire][date]', 'value' => date('Y-m-d\\TH:i', $block['expire'] ?: TIME)])])]), $block['type'] == 'html' ? h::{'td[colspan=5] textarea.EDITOR'}(get_block_content($rc[3]), ['name' => 'block[html]']) : ($block['type'] == 'raw_html' ? h::{'td[colspan=5] textarea'}(get_block_content($rc[3]), ['name' => 'block[raw_html]']) : '')) . h::{'input[type=hidden]'}([[['name' => 'block[id]', 'value' => $rc[3]]], [['name' => 'mode', 'value' => $rc[2]]]]));
     break;
 case 'permissions':
     if (!isset($rc[3], $Config->components['blocks'][$rc[3]])) {
         break;
     }
     $form = false;
     $a->apply_button = false;
     $a->cancel_button_back = true;
     $permission = Permission::instance()->get(null, 'Block', $Config->components['blocks'][$rc[3]]['index'])[0]['id'];
     $groups = Group::instance()->get_all();
     $groups_content = [];
     foreach ($groups as $group) {
         $group_permission = $User->db()->qfs(["SELECT `value`\n\t\t\t\t\tFROM `[prefix]groups_permissions`\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`id`\t\t\t= '%s' AND\n\t\t\t\t\t\t`permission`\t= '%s'", $group['id'], $permission]);
         $groups_content[] = h::th($group['title'], ['data-title' => $group['description']]) . h::{'td input[type=radio]'}(['name' => "groups[{$group['id']}]", 'checked' => $group_permission === false ? -1 : $group_permission, 'value' => [-1, 0, 1], 'in' => [$L->inherited, $L->deny, $L->allow]]);
     }
     unset($groups, $group, $group_permission);
     if (count($groups_content) % 2) {
         $groups_content[] = h::{'td[colspan=2]'}();
     }
     $count = count($groups_content);
     $content_ = [];
     for ($i = 0; $i < $count; $i += 2) {
         $content_[] = $groups_content[$i] . $groups_content[$i + 1];
     }
示例#4
0
 /**
  * Get permission state for specified user
  *
  * Rule: if not denied - allowed (users), if not allowed - denied (admins)
  *
  * @param string	$group	Permission group
  * @param string	$label	Permission label
  * @param bool|int	$user	If not specified - current user assumed
  *
  * @return bool				If permission exists - returns its state for specified user, otherwise for admin permissions returns <b>false</b> and for
  * 							others <b>true</b>
  */
 function get_permission($group, $label, $user = false)
 {
     $user = (int) ($user ?: $this->id);
     if ($this->system() || $user == self::ROOT_ID) {
         return true;
     }
     if (!$user) {
         return false;
     }
     if (!isset($this->permissions[$user])) {
         $this->permissions[$user] = $this->cache->get("permissions/{$user}", function () use($user) {
             $permissions = [];
             if ($user != self::GUEST_ID) {
                 $groups = $this->get_groups($user);
                 if (is_array($groups)) {
                     $Group = Group::instance();
                     foreach ($groups as $group_id) {
                         foreach ($Group->get_permissions($group_id) ?: [] as $p => $v) {
                             $permissions[$p] = $v;
                         }
                         unset($p, $v);
                     }
                 }
                 unset($groups, $group_id);
             }
             foreach ($this->get_permissions($user) ?: [] as $p => $v) {
                 $permissions[$p] = $v;
             }
             return $permissions;
         });
     }
     $all_permission = Cache::instance()->{'permissions/all'} ?: Permission::instance()->get_all();
     if (isset($all_permission[$group], $all_permission[$group][$label])) {
         $permission = $all_permission[$group][$label];
         if (isset($this->permissions[$user][$permission])) {
             return (bool) $this->permissions[$user][$permission];
         } else {
             return $this->admin() ? true : strpos($group, 'admin/') !== 0;
         }
     } else {
         return true;
     }
 }