/** * Get the HTML snippet for table specific privileges * * @param string $username username for database connection * @param string $hostname hostname for database connection * @param string $db the database * @param string $table the table * @param array $columns columns array * @param array $row current privileges row * * @return string $html_output */ function PMA_getHtmlForTableSpecificPrivileges($username, $hostname, $db, $table, $columns, $row) { $res = $GLOBALS['dbi']->query('SELECT `Column_name`, `Column_priv`' . ' FROM `mysql`.`columns_priv`' . ' WHERE `User`' . ' = \'' . PMA_Util::sqlAddSlashes($username) . "'" . ' AND `Host`' . ' = \'' . PMA_Util::sqlAddSlashes($hostname) . "'" . ' AND `Db`' . ' = \'' . PMA_Util::sqlAddSlashes(PMA_Util::unescapeMysqlWildcards($db)) . "'" . ' AND `Table_name`' . ' = \'' . PMA_Util::sqlAddSlashes($table) . '\';'); while ($row1 = $GLOBALS['dbi']->fetchRow($res)) { $row1[1] = explode(',', $row1[1]); foreach ($row1[1] as $current) { $columns[$row1[0]][$current] = true; } } $GLOBALS['dbi']->freeResult($res); unset($res, $row1, $current); $html_output = '<input type="hidden" name="grant_count" ' . 'value="' . count($row) . '" />' . "\n" . '<input type="hidden" name="column_count" ' . 'value="' . count($columns) . '" />' . "\n" . '<fieldset id="fieldset_user_priv">' . "\n" . '<legend data-submenu-label="Table">' . __('Table-specific privileges') . PMA_Util::showHint(__('Note: MySQL privilege names are expressed in English.')) . '</legend>' . "\n"; // privs that are attached to a specific column $html_output .= PMA_getHtmlForAttachedPrivilegesToTableSpecificColumn($columns, $row); // privs that are not attached to a specific column $html_output .= '<div class="item">' . "\n" . PMA_getHtmlForNotAttachedPrivilegesToTableSpecificColumn($row) . '</div>' . "\n"; // for Safari 2.0.2 $html_output .= '<div class="clearfloat"></div>' . "\n"; return $html_output; }
/** * Test for PMA_getHtmlForTableSpecificPrivileges * * @return void */ public function testPMAGetHtmlForTableSpecificPrivileges() { $GLOBALS['strPrivDescCreate_viewTbl'] = "strPrivDescCreate_viewTbl"; $GLOBALS['strPrivDescShowViewTbl'] = "strPrivDescShowViewTbl"; $username = "******"; $hostname = "PMA_hostname"; $db = "PMA_db"; $table = "PMA_table"; $columns = array('row1' => 'name1'); $row = array('Select_priv' => 'Y', 'Insert_priv' => 'Y', 'Update_priv' => 'Y', 'References_priv' => 'Y', 'Create_view_priv' => 'Y', 'ShowView_priv' => 'Y'); $html = PMA_getHtmlForTableSpecificPrivileges($username, $hostname, $db, $table, $columns, $row); //validate 1: PMA_getHtmlForAttachedPrivilegesToTableSpecificColumn $item = PMA_getHtmlForAttachedPrivilegesToTableSpecificColumn($columns, $row); $this->assertContains($item, $html); $this->assertContains(__('Allows reading data.'), $html); $this->assertContains(__('Allows inserting and replacing data'), $html); $this->assertContains(__('Allows changing data.'), $html); $this->assertContains(__('Has no effect in this MySQL version.'), $html); //validate 2: PMA_getHtmlForNotAttachedPrivilegesToTableSpecificColumn $item = PMA_getHtmlForNotAttachedPrivilegesToTableSpecificColumn($row); $this->assertContains($item, $html); $this->assertContains('Create_view_priv', $html); $this->assertContains('ShowView_priv', $html); }