| Conditions | 36 |
| Paths | 16800 |
| Total Lines | 214 |
| Code Lines | 142 |
| 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 |
||
| 58 | public function doDefault($msg = '') |
||
| 59 | { |
||
| 60 | $conf = $this->conf; |
||
| 61 | |||
| 62 | $lang = $this->lang; |
||
| 63 | $action = $this->action; |
||
| 64 | $data = $this->misc->getDatabaseAccessor(); |
||
| 65 | $database = $this->misc->getDatabase(); |
||
| 66 | |||
| 67 | $this->printTrail($_REQUEST['subject']); |
||
| 68 | |||
| 69 | // @@@FIXME: This switch is just a temporary solution, |
||
| 70 | // need a better way, maybe every type of object should |
||
| 71 | // have a tab bar??? |
||
| 72 | switch ($_REQUEST['subject']) { |
||
| 73 | case 'server': |
||
| 74 | case 'database': |
||
| 75 | case 'schema': |
||
| 76 | case 'table': |
||
| 77 | case 'column': |
||
| 78 | case 'view': |
||
| 79 | $this->printTabs($_REQUEST['subject'], 'privileges'); |
||
| 80 | |||
| 81 | break; |
||
| 82 | default: |
||
| 83 | $this->printTitle($lang['strprivileges'], 'pg.privilege'); |
||
| 84 | } |
||
| 85 | $this->printMsg($msg); |
||
| 86 | |||
| 87 | // Determine whether object should be ref'd by name or oid. |
||
| 88 | if (isset($_REQUEST[$_REQUEST['subject'].'_oid'])) { |
||
| 89 | $object = $_REQUEST[$_REQUEST['subject'].'_oid']; |
||
| 90 | } else { |
||
| 91 | $object = $_REQUEST[$_REQUEST['subject']]; |
||
| 92 | } |
||
| 93 | |||
| 94 | // Get the privileges on the object, given its type |
||
| 95 | if ('column' == $_REQUEST['subject']) { |
||
| 96 | $privileges = $data->getPrivileges($object, 'column', $_REQUEST['table']); |
||
| 97 | } else { |
||
| 98 | $privileges = $data->getPrivileges($object, $_REQUEST['subject']); |
||
| 99 | } |
||
| 100 | |||
| 101 | if (sizeof($privileges) > 0) { |
||
| 102 | echo "<table>\n"; |
||
| 103 | if ($data->hasRoles()) { |
||
| 104 | echo "<tr><th class=\"data\">{$lang['strrole']}</th>"; |
||
| 105 | } else { |
||
| 106 | echo "<tr><th class=\"data\">{$lang['strtype']}</th><th class=\"data\">{$lang['struser']}/{$lang['strgroup']}</th>"; |
||
| 107 | } |
||
| 108 | |||
| 109 | foreach ($data->privlist[$_REQUEST['subject']] as $v2) { |
||
| 110 | // Skip over ALL PRIVILEGES |
||
| 111 | if ('ALL PRIVILEGES' == $v2) { |
||
| 112 | continue; |
||
| 113 | } |
||
| 114 | |||
| 115 | echo "<th class=\"data\">{$v2}</th>\n"; |
||
| 116 | } |
||
| 117 | if ($data->hasGrantOption()) { |
||
| 118 | echo "<th class=\"data\">{$lang['strgrantor']}</th>"; |
||
| 119 | } |
||
| 120 | echo "</tr>\n"; |
||
| 121 | |||
| 122 | // Loop over privileges, outputting them |
||
| 123 | $i = 0; |
||
| 124 | foreach ($privileges as $v) { |
||
| 125 | $id = (0 == ($i % 2) ? '1' : '2'); |
||
| 126 | echo "<tr class=\"data{$id}\">\n"; |
||
| 127 | if (!$data->hasRoles()) { |
||
| 128 | echo '<td>', $this->misc->printVal($v[0]), "</td>\n"; |
||
| 129 | } |
||
| 130 | |||
| 131 | echo '<td>', $this->misc->printVal($v[1]), "</td>\n"; |
||
| 132 | foreach ($data->privlist[$_REQUEST['subject']] as $v2) { |
||
| 133 | // Skip over ALL PRIVILEGES |
||
| 134 | if ('ALL PRIVILEGES' == $v2) { |
||
| 135 | continue; |
||
| 136 | } |
||
| 137 | |||
| 138 | echo '<td>'; |
||
| 139 | if (in_array($v2, $v[2], true)) { |
||
| 140 | echo $lang['stryes']; |
||
| 141 | } else { |
||
| 142 | echo $lang['strno']; |
||
| 143 | } |
||
| 144 | |||
| 145 | // If we have grant option for this, end mark |
||
| 146 | if ($data->hasGrantOption() && in_array($v2, $v[4], true)) { |
||
| 147 | echo $lang['strasterisk']; |
||
| 148 | } |
||
| 149 | |||
| 150 | echo "</td>\n"; |
||
| 151 | } |
||
| 152 | if ($data->hasGrantOption()) { |
||
| 153 | echo '<td>', $this->misc->printVal($v[3]), "</td>\n"; |
||
| 154 | } |
||
| 155 | echo "</tr>\n"; |
||
| 156 | ++$i; |
||
| 157 | } |
||
| 158 | |||
| 159 | echo '</table>'; |
||
| 160 | } else { |
||
| 161 | echo "<p>{$lang['strnoprivileges']}</p>\n"; |
||
| 162 | } |
||
| 163 | |||
| 164 | // Links for granting to a user or group |
||
| 165 | switch ($_REQUEST['subject']) { |
||
| 166 | case 'table': |
||
| 167 | case 'view': |
||
| 168 | case 'sequence': |
||
| 169 | case 'function': |
||
| 170 | case 'tablespace': |
||
| 171 | $alllabel = "showall{$_REQUEST['subject']}s"; |
||
| 172 | $allurl = "{$_REQUEST['subject']}s.php"; |
||
| 173 | $alltxt = $lang["strshowall{$_REQUEST['subject']}s"]; |
||
| 174 | |||
| 175 | break; |
||
| 176 | case 'schema': |
||
| 177 | $alllabel = 'showallschemas'; |
||
| 178 | $allurl = 'schemas.php'; |
||
| 179 | $alltxt = $lang['strshowallschemas']; |
||
| 180 | |||
| 181 | break; |
||
| 182 | case 'database': |
||
| 183 | $alllabel = 'showalldatabases'; |
||
| 184 | $allurl = 'alldb.php'; |
||
| 185 | $alltxt = $lang['strshowalldatabases']; |
||
| 186 | |||
| 187 | break; |
||
| 188 | } |
||
| 189 | |||
| 190 | $subject = $_REQUEST['subject']; |
||
| 191 | $object = $_REQUEST[$_REQUEST['subject']]; |
||
| 192 | |||
| 193 | if ('function' == $_REQUEST['subject']) { |
||
| 194 | $objectoid = $_REQUEST[$_REQUEST['subject'].'_oid']; |
||
| 195 | $urlvars = [ |
||
| 196 | 'action' => 'alter', |
||
| 197 | 'server' => $_REQUEST['server'], |
||
| 198 | 'database' => $_REQUEST['database'], |
||
| 199 | 'schema' => $_REQUEST['schema'], |
||
| 200 | $subject => $object, |
||
| 201 | "{$subject}_oid" => $objectoid, |
||
| 202 | 'subject' => $subject, |
||
| 203 | ]; |
||
| 204 | } elseif ('column' == $_REQUEST['subject']) { |
||
| 205 | $urlvars = [ |
||
| 206 | 'action' => 'alter', |
||
| 207 | 'server' => $_REQUEST['server'], |
||
| 208 | 'database' => $_REQUEST['database'], |
||
| 209 | 'schema' => $_REQUEST['schema'], |
||
| 210 | $subject => $object, |
||
| 211 | 'subject' => $subject, |
||
| 212 | ]; |
||
| 213 | |||
| 214 | if (isset($_REQUEST['table'])) { |
||
| 215 | $urlvars['table'] = $_REQUEST['table']; |
||
| 216 | } else { |
||
| 217 | $urlvars['view'] = $_REQUEST['view']; |
||
| 218 | } |
||
| 219 | } else { |
||
| 220 | $urlvars = [ |
||
| 221 | 'action' => 'alter', |
||
| 222 | 'server' => $_REQUEST['server'], |
||
| 223 | 'database' => $_REQUEST['database'], |
||
| 224 | $subject => $object, |
||
| 225 | 'subject' => $subject, |
||
| 226 | ]; |
||
| 227 | if (isset($_REQUEST['schema'])) { |
||
| 228 | $urlvars['schema'] = $_REQUEST['schema']; |
||
| 229 | } |
||
| 230 | } |
||
| 231 | |||
| 232 | $navlinks = [ |
||
| 233 | 'grant' => [ |
||
| 234 | 'attr' => [ |
||
| 235 | 'href' => [ |
||
| 236 | 'url' => 'privileges.php', |
||
| 237 | 'urlvars' => array_merge($urlvars, ['mode' => 'grant']), |
||
| 238 | ], |
||
| 239 | ], |
||
| 240 | 'content' => $lang['strgrant'], |
||
| 241 | ], |
||
| 242 | 'revoke' => [ |
||
| 243 | 'attr' => [ |
||
| 244 | 'href' => [ |
||
| 245 | 'url' => 'privileges.php', |
||
| 246 | 'urlvars' => array_merge($urlvars, ['mode' => 'revoke']), |
||
| 247 | ], |
||
| 248 | ], |
||
| 249 | 'content' => $lang['strrevoke'], |
||
| 250 | ], |
||
| 251 | ]; |
||
| 252 | |||
| 253 | if (isset($allurl)) { |
||
| 254 | $navlinks[$alllabel] = [ |
||
| 255 | 'attr' => [ |
||
| 256 | 'href' => [ |
||
| 257 | 'url' => $allurl, |
||
| 258 | 'urlvars' => [ |
||
| 259 | 'server' => $_REQUEST['server'], |
||
| 260 | 'database' => $_REQUEST['database'], |
||
| 261 | ], |
||
| 262 | ], |
||
| 263 | ], |
||
| 264 | 'content' => $alltxt, |
||
| 265 | ]; |
||
| 266 | if (isset($_REQUEST['schema'])) { |
||
| 267 | $navlinks[$alllabel]['attr']['href']['urlvars']['schema'] = $_REQUEST['schema']; |
||
| 268 | } |
||
| 269 | } |
||
| 270 | |||
| 271 | $this->printNavLinks($navlinks, $this->table_place, get_defined_vars()); |
||
| 272 | } |
||
| 433 |