Exemple #1
0
 public function admin()
 {
     if (!Base_AclCommon::i_am_sa() || $this->is_back()) {
         $this->parent->reset();
         return;
     }
     Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href());
     $cmr = ModuleManager::call_common_methods('admin_caption');
     foreach ($cmr as $name => $caption) {
         if (!ModuleManager::check_access($name, 'admin') || $name == 'Base_Admin') {
             continue;
         }
         if (!isset($caption)) {
             continue;
         }
         if (!is_array($caption)) {
             $caption = array('label' => $caption);
         }
         if (!isset($caption['section'])) {
             $caption['section'] = __('Misc');
         }
         $mod_ok[$name] = $caption;
     }
     uksort($mod_ok, 'strcasecmp');
     $form = $this->init_module('Libs_QuickForm');
     $buttons = array();
     load_js('modules/Base/Admin/js/main.js');
     foreach ($mod_ok as $name => $caption) {
         if (method_exists($name . 'Common', 'admin_icon')) {
             $icon = call_user_func(array($name . 'Common', 'admin_icon'));
         } else {
             $icon = Base_ThemeCommon::get_template_file($name, 'icon.png');
             if (!file_exists($icon)) {
                 $icon = Base_ThemeCommon::get_template_file('Base_Admin', 'icon.png');
             }
         }
         $button_id = $name . '__button';
         $enable_field = $name . '_enable';
         $sections = array();
         $sections_id = $name . '__sections';
         $enable_default = Base_AdminCommon::get_access($name, '', true);
         $form->addElement('checkbox', $enable_field, $enable_default === null ? __('Access blocked') : __('Allow access'), null, array('onchange' => 'admin_switch_button("' . $button_id . '",this.checked, "' . $sections_id . '");', 'id' => $enable_field, 'style' => $enable_default === null ? 'display:none;' : ''));
         $form->setDefaults(array($enable_field => $enable_default));
         eval_js('admin_switch_button("' . $button_id . '",$("' . $enable_field . '").checked, "' . $sections_id . '", 1);');
         if (class_exists($name . 'Common') && is_callable(array($name . 'Common', 'admin_access_levels'))) {
             $raws = call_user_func(array($name . 'Common', 'admin_access_levels'));
             if (is_array($raws)) {
                 foreach ($raws as $s => $v) {
                     $type = isset($v['values']) ? 'select' : 'checkbox';
                     $vals = isset($v['values']) ? $v['values'] : null;
                     $s_field = $name . '__' . $s . '__switch';
                     $form->addElement($type, $s_field, $v['label'], $vals);
                     $form->setDefaults(array($s_field => Base_AdminCommon::get_access($name, $s, true)));
                     $sections[$s] = $s_field;
                 }
             }
         }
         $buttons[$caption['section']][$name] = array('label' => $caption['label'], 'icon' => $icon, 'id' => $button_id, 'enable_switch' => $enable_field, 'sections_id' => $sections_id, 'sections' => $sections);
     }
     if ($form->validate()) {
         $vals = $form->exportValues();
         DB::Execute('DELETE FROM base_admin_access');
         foreach ($buttons as $section => $bs) {
             foreach ($bs as $name => $b) {
                 DB::Execute('INSERT INTO base_admin_access (module, section, allow) VALUES (%s, %s, %d)', array($name, '', isset($vals[$b['enable_switch']]) && $vals[$b['enable_switch']] ? 1 : 0));
                 foreach ($b['sections'] as $s => $f) {
                     DB::Execute('INSERT INTO base_admin_access (module, section, allow) VALUES (%s, %s, %d)', array($name, $s, isset($vals[$f]) ? $vals[$f] : 0));
                 }
             }
         }
         $this->parent->reset();
         return;
     }
     Base_ActionBarCommon::add('save', __('Save'), $form->get_submit_form_href());
     $sections = array();
     foreach ($buttons as $section => $b) {
         $sections[$section] = array('header' => $section, 'buttons' => $b);
     }
     $sections = $this->sort_sections($sections);
     $theme = $this->pack_module('Base/Theme');
     $form->assign_theme('form', $theme);
     $theme->assign('header', __('Admin Panel Access'));
     $theme->assign('sections', $sections);
     $theme->display('access_panel');
 }
Exemple #2
0
 /**
  * Checks access to function which name is passed as first parameter.
  * 
  * If you want to restric access to a function just make function named
  * 'functionname_access' returning false if user should not access this function.
  * 
  * This function is called automatically with each pack_module call.
  * 
  * @param string function name
  * @return bool true if access is granted, false otherwise
  */
 public final function check_access($m)
 {
     return ModuleManager::check_access($this->type, $m);
 }