| Conditions | 18 |
| Paths | 340 |
| Total Lines | 108 |
| Code Lines | 67 |
| 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 |
||
| 143 | function index(array $content=null, $msg='', $sessions_list=false) |
||
| 144 | { |
||
| 145 | |||
| 146 | if (is_array($content)) $sessions_list = $content['nm']['session_list']; |
||
| 147 | |||
| 148 | // check if user has access to requested functionality |
||
| 149 | if ($GLOBALS['egw']->acl->check($sessions_list ? 'current_sessions' : 'access_log_acces',1,'admin')) |
||
| 150 | { |
||
| 151 | $GLOBALS['egw']->redirect_link('/index.php'); |
||
| 152 | } |
||
| 153 | |||
| 154 | if(!isset($content)) |
||
| 155 | { |
||
| 156 | $content['nm'] = array( |
||
| 157 | 'get_rows' => 'admin.admin_accesslog.get_rows', // I method/callback to request the data for the rows eg. 'notes.bo.get_rows' |
||
| 158 | 'no_filter' => True, // I disable the 1. filter |
||
| 159 | 'no_filter2' => True, // I disable the 2. filter (params are the same as for filter) |
||
| 160 | 'no_cat' => True, // I disable the cat-selectbox |
||
| 161 | 'header_left' => false, // I template to show left of the range-value, left-aligned (optional) |
||
| 162 | 'header_right' => false, // I template to show right of the range-value, right-aligned (optional) |
||
| 163 | 'never_hide' => True, // I never hide the nextmatch-line if less then maxmatch entries |
||
| 164 | 'lettersearch' => false, // I show a lettersearch |
||
| 165 | 'start' => 0, // IO position in list |
||
| 166 | 'order' => 'li', // IO name of the column to sort after (optional for the sortheaders) |
||
| 167 | 'sort' => 'DESC', // IO direction of the sort: 'ASC' or 'DESC' |
||
| 168 | 'default_cols' => '!session_action', // I columns to use if there's no user or default pref (! as first char uses all but the named columns), default all columns |
||
| 169 | 'csv_fields' => false, // I false=disable csv export, true or unset=enable it with auto-detected fieldnames, |
||
| 170 | //or array with name=>label or name=>array('label'=>label,'type'=>type) pairs (type is a eT widget-type) |
||
| 171 | 'actions' => $this->get_actions($sessions_list), |
||
| 172 | 'placeholder_actions' => false, |
||
| 173 | 'row_id' => 'sessionid', |
||
| 174 | ); |
||
| 175 | if ((int)$_GET['account_id']) |
||
| 176 | { |
||
| 177 | $content['nm']['col_filter']['account_id'] = (int)$_GET['account_id']; |
||
| 178 | } |
||
| 179 | if ($sessions_list) |
||
| 180 | { |
||
| 181 | $content['nm']['order'] = 'session_dla'; |
||
| 182 | $content['nm']['options-selectcols'] = array( |
||
| 183 | 'lo' => false, |
||
| 184 | 'total' => false, |
||
| 185 | ); |
||
| 186 | } |
||
| 187 | $content['nm']['session_list'] = $sessions_list; |
||
| 188 | } |
||
| 189 | //error_log(__METHOD__. ' accesslog =>' . array2string($content['nm']['selected'])); |
||
| 190 | if ($content['nm']['action']) |
||
| 191 | { |
||
| 192 | if ($content['nm']['select_all']) |
||
| 193 | { |
||
| 194 | // get the whole selection |
||
| 195 | $query = array( |
||
| 196 | 'search' => $content['nm']['search'], |
||
| 197 | 'col_filter' => $content['nm']['col_filter'] |
||
| 198 | ); |
||
| 199 | |||
| 200 | @set_time_limit(0); // switch off the execution time limit, as it's for big selections to small |
||
|
|
|||
| 201 | $query['num_rows'] = -1; // all |
||
| 202 | $all = $readonlys = array(); |
||
| 203 | $this->get_rows($query,$all,$readonlys); |
||
| 204 | $content['nm']['selected'] = array(); |
||
| 205 | foreach($all as $session) |
||
| 206 | { |
||
| 207 | $content['nm']['selected'][] = $session[$content['nm']['row_id']]; |
||
| 208 | } |
||
| 209 | } |
||
| 210 | if (!count($content['nm']['selected']) && !$content['nm']['select_all']) |
||
| 211 | { |
||
| 212 | $msg = lang('You need to select some entries first!'); |
||
| 213 | } |
||
| 214 | else |
||
| 215 | { |
||
| 216 | $success = $failed = $action = $action_msg = null; |
||
| 217 | if ($this->action($content['nm']['action'],$content['nm']['selected'] |
||
| 218 | ,$success,$failed,$action_msg,$msg)) |
||
| 219 | { // In case of action success |
||
| 220 | switch ($action_msg) |
||
| 221 | { |
||
| 222 | case'deleted': |
||
| 223 | $msg = lang('%1 log entries deleted.',$success); |
||
| 224 | break; |
||
| 225 | case'killed': |
||
| 226 | $msg = lang('%1 sessions killed',$success); |
||
| 227 | } |
||
| 228 | } |
||
| 229 | elseif($failed) // In case of action failiure |
||
| 230 | { |
||
| 231 | switch ($action_msg) |
||
| 232 | { |
||
| 233 | case'deleted': |
||
| 234 | $msg = lang('Error deleting log entry!'); |
||
| 235 | break; |
||
| 236 | case'killed': |
||
| 237 | $msg = lang('Permission denied!'); |
||
| 238 | } |
||
| 239 | } |
||
| 240 | } |
||
| 241 | } |
||
| 242 | |||
| 243 | $content['msg'] = $msg; |
||
| 244 | $content['percent'] = 100.0 * $GLOBALS['egw']->db->query( |
||
| 245 | 'SELECT ((SELECT COUNT(*) FROM '.self::TABLE.' WHERE lo != 0) / COUNT(*)) FROM '.self::TABLE, |
||
| 246 | __LINE__,__FILE__)->fetchColumn(); |
||
| 247 | |||
| 248 | $tmpl = new Etemplate('admin.accesslog'); |
||
| 249 | $tmpl->exec('admin.admin_accesslog.index', $content, array(), $readonlys, array( |
||
| 250 | 'nm' => $content['nm'], |
||
| 251 | )); |
||
| 370 |
If you suppress an error, we recommend checking for the error condition explicitly: