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