Example #1
0
 protected function renderContextItem($arr)
 {
     $items = "";
     $def_items = array('add' => array('fn' => "function(){ \${$this->grid_full_id}.jqGrid('editGridRow','new', {serializeEditData:function(post) { post.className = \${$this->grid_full_id}.jqGrid('getPostDataItem', 'className'); return post;}, closeAfterAdd:true}); }", 'text' => 'Добавить', 'iconClass' => 'add_icon'), 'edit' => array('fn' => "function(id){ \${$this->grid_full_id}.jqGrid('editGridRow',id, {serializeEditData:function(post) { post.className = \${$this->grid_full_id}.jqGrid('getPostDataItem', 'className'); return post;}, closeAfterEdit:true}); }", 'text' => 'Редактировать', 'iconClass' => 'edit_icon'), 'del' => array('fn' => "function(id){ \${$this->grid_full_id}.jqGrid('delGridRow',id, {serializeDelData:function(post) { post.className = \${$this->grid_full_id}.jqGrid('getPostDataItem', 'className'); return post;}}); }", 'text' => 'Удалить', 'iconClass' => 'delete_icon'));
     foreach ($arr as $k => $v) {
         $id = is_numeric($k) ? $v : $k;
         $def = is_numeric($k) ? array() : $v;
         if (!empty($def_items[$id])) {
             $def = array_merge($def_items[$id], $def);
         }
         if (!empty($def['grant']) && !user_bo::grant($def['grant'], false)) {
             continue;
         }
         $items .= "'{$id}': {name: '{$def['text']}',";
         if (isset($def['fn'])) {
             $items .= "callback: function() { var fn={$def['fn']}; fn(\${$this->grid_full_id}.jqGrid('getSelected')); },";
         }
         if (isset($def['iconClass'])) {
             $items .= "className: '{$def['iconClass']}',";
         }
         // условие hideIf
         if (isset($def['hideIf'])) {
             foreach ($def['hideIf'] as $k => &$v) {
                 if (!is_array($v)) {
                     $v = array($v);
                 }
                 foreach ($v as &$i) {
                     $i = strval($i);
                 }
             }
             $items .= "hideIf:" . json_encode($def['hideIf']);
         }
         // условие showIf
         if (isset($def['showIf'])) {
             foreach ($def['showIf'] as $k => &$v) {
                 if (!is_array($v)) {
                     $v = array($v);
                 }
                 foreach ($v as &$i) {
                     $i = strval($i);
                 }
             }
             $items .= "showIf:" . json_encode($def['showIf']);
         }
         if (!empty($def['items'])) {
             $items .= "items:" . $this->renderContextItem($def['items']);
         }
         $items .= "},";
     }
     $items = "{" . trim($items, ',') . "}";
     return $items;
 }
Example #2
0
 private function getAllowedSections()
 {
     $sect = array();
     $session_user_groups = user_bo::getSessionUserGroups();
     foreach (constData::$data['sections'] as $k => $s) {
         $s['groups'] = isset($s['groups']) ? array_merge($s['groups'], array('admin')) : array();
         $s['limit_buttons'] = isset($s['limit_buttons']) ? $s['limit_buttons'] : 7;
         $s['sysname'] = $k;
         if ($k == 'common') {
             $sect[$k] = $s;
         } elseif (!$s['groups'] and !in_array('strict', $session_user_groups) or in_array('admin', $session_user_groups) or array_intersect($session_user_groups, $s['groups'])) {
             $sect[$k] = $s;
         } else {
             continue;
         }
         $no_ruled_groups = empty($sect[$k]['rules']) == false ? array_diff($sect[$k]['groups'], array_keys($sect[$k]['rules'])) : (!empty($sect[$k]['groups']) ? $sect[$k]['groups'] : array());
         foreach ($no_ruled_groups as $g) {
             $sect[$k]['rules'][$g] = array_keys($sect[$k]['items']);
         }
         if (empty($sect[$k]['rules'])) {
             $sect[$k]['rules'] = array();
         }
         #Apply rules
         $allowed_act = array();
         foreach (array_intersect(array_keys($sect[$k]['rules']), $session_user_groups) as $g) {
             $allowed_act = array_merge($allowed_act, $sect[$k]['rules'][$g]);
         }
         if ($allowed_act) {
             $sect[$k]['items'] = array_intersect_key($sect[$k]['items'], array_flip($allowed_act));
         }
     }
     // Т.к. видеть админку могут все, если заполнено поле view_groups,
     // то отключаем "настройки" и "группы" у неадминов тут
     //die(var_dump(user_bo::getSessionUser()));
     if (isset($sect['admin'])) {
         if (!user_bo::is('admin')) {
             $possible_items = array();
             if (user_bo::is('create_users')) {
                 $possible_items = array('bouser', 'group');
             } elseif (count(user_bo::getSessionUserViewGroups()) > 0) {
                 $possible_items = array('bouser');
             }
             // Скрываем недоступные вкладки
             foreach ($sect['admin']['items'] as $key => $value) {
                 if (!in_array($key, $possible_items)) {
                     unset($sect['admin']['items'][$key]);
                 }
             }
             // Если нет доступных вкладок, то админку не показываем
             if (count($sect['admin']['items']) == 0) {
                 unset($sect['admin']);
             }
         }
     }
     return $sect;
 }