| Conditions | 10 |
| Paths | 16 |
| Total Lines | 66 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 107 | function access_form() |
||
| 108 | { |
||
| 109 | $location = $_GET['location']; |
||
| 110 | |||
| 111 | // for POST (not GET or cli call via setup_cmd_admin) validate CSRF token |
||
| 112 | if ($_SERVER['REQUEST_METHOD'] == 'POST') |
||
| 113 | { |
||
| 114 | Api\Csrf::validate($_POST['csrf_token'], __FILE__); |
||
| 115 | } |
||
| 116 | if ($_POST['submit'] || $_POST['cancel']) |
||
| 117 | { |
||
| 118 | if ($_POST['submit']) |
||
| 119 | { |
||
| 120 | $total_rights = 0; |
||
| 121 | if (is_array($_POST['acl_rights'])) |
||
| 122 | { |
||
| 123 | foreach($_POST['acl_rights'] as $rights) |
||
| 124 | { |
||
| 125 | $total_rights += $rights; |
||
| 126 | } |
||
| 127 | } |
||
| 128 | if ($total_rights) |
||
| 129 | { |
||
| 130 | $GLOBALS['egw']->acl->add_repository($_GET['acl_app'], $location, $this->account_id, $total_rights); |
||
| 131 | } |
||
| 132 | else // we dont need to save 0 rights (= no restrictions) |
||
| 133 | { |
||
| 134 | $GLOBALS['egw']->acl->delete_repository($_GET['acl_app'], $location, $this->account_id); |
||
| 135 | } |
||
| 136 | } |
||
| 137 | $this->list_apps(); |
||
| 138 | return; |
||
| 139 | } |
||
| 140 | Api\Hooks::single('acl_manager',$_GET['acl_app']); |
||
| 141 | $acl_manager = $GLOBALS['acl_manager'][$_GET['acl_app']][$location]; |
||
| 142 | |||
| 143 | $this->common_header(); |
||
| 144 | $this->template->set_file('form','acl_manager_form.tpl'); |
||
| 145 | $this->template->set_var('csrf_token', Api\Csrf::token(__FILE__)); |
||
| 146 | |||
| 147 | $afn = Api\Accounts::username($this->account_id); |
||
| 148 | |||
| 149 | $this->template->set_var('lang_message',lang('Check items to <b>%1</b> to %2 for %3',lang($acl_manager['name']),$GLOBALS['egw_info']['apps'][$_GET['acl_app']]['title'],$afn)); |
||
| 150 | $link_values = array( |
||
| 151 | 'menuaction' => 'admin.admin_denyaccess.access_form', |
||
| 152 | 'acl_app' => $_GET['acl_app'], |
||
| 153 | 'location' => urlencode($_GET['location']), |
||
| 154 | 'account_id' => $this->account_id |
||
| 155 | ); |
||
| 156 | |||
| 157 | $acl = new Api\Acl($this->account_id); |
||
| 158 | $acl->read_repository(); |
||
| 159 | $grants = $acl->get_rights($location,$_GET['acl_app']); |
||
| 160 | |||
| 161 | $this->template->set_var('form_action',$GLOBALS['egw']->link('/index.php',$link_values)); |
||
| 162 | |||
| 163 | foreach($acl_manager['rights'] as $name => $value) |
||
| 164 | { |
||
| 165 | $cb .= '<input type="checkbox" name="acl_rights[]" value="'.$value.'"'.($grants & $value ? ' checked' : '').'> '.lang($name)."<br>\n"; |
||
| 166 | } |
||
| 167 | $this->template->set_var('select_values',$cb); |
||
| 168 | $this->template->set_var('lang_submit',lang('Save')); |
||
| 169 | $this->template->set_var('lang_cancel',lang('Cancel')); |
||
| 170 | |||
| 171 | $this->template->pfp('out','form'); |
||
| 172 | echo $GLOBALS['egw']->framework->footer(); |
||
| 173 | } |
||
| 175 |