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