2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Displays form for creating a table (if user has privileges for that)
8 if (! defined('PHPMYADMIN')) {
15 require_once './libraries/check_user_privileges.lib.php';
17 // for MySQL >= 4.1.0, we should be able to detect if user has a CREATE
18 // privilege by looking at SHOW GRANTS output;
19 // for < 4.1.0, it could be more difficult because the logic tries to
20 // detect the current host and it might be expressed in many ways; also
21 // on a shared server, the user might be unable to define a controluser
22 // that has the proper rights to the "mysql" db;
23 // so we give up and assume that user has the right to create a table
25 // Note: in this case we could even skip the following "foreach" logic
27 // Addendum, 2006-01-19: ok, I give up. We got some reports about servers
28 // where the hostname field in mysql.user is not the same as the one
29 // in mysql.db for a user. In this case, SHOW GRANTS does not return
30 // the db-specific privileges. And probably, those users are on a shared
31 // server, so can't set up a control user with rights to the "mysql" db.
32 // We cannot reliably detect the db-specific privileges, so no more
33 // warnings about the lack of privileges for CREATE TABLE. Tested
36 $is_create_table_priv = true;
39 if (PMA_MYSQL_INT_VERSION >= 40100) {
40 $is_create_table_priv = false;
42 $is_create_table_priv = true;
45 foreach ($dbs_where_create_table_allowed as $allowed_db) {
47 // if we find the exact db name, we stop here
48 if ($allowed_db == $db) {
49 $is_create_table_priv = TRUE;
53 // '*' indicates a global CREATE priv
54 if ($allowed_db == '*') {
55 $is_create_table_priv = TRUE;
59 if (ereg('%|_', $allowed_db)) {
60 // take care of wildcards and escaped wildcards,
61 // transforming them into regexp patterns
62 $max_position = strlen($allowed_db) - 1;
65 while ($i <= $max_position) {
66 if ($allowed_db[$i] == '\\'){
67 if ($i < $max_position - 1 && $allowed_db[$i+1] == '_'){
70 } elseif ($i < $max_position - 1 && $allowed_db[$i+1] == '%'){
74 $chunk = $allowed_db[$i];
76 } elseif ($allowed_db[$i] == '_'){
78 } elseif ($allowed_db[$i] == '%'){
81 $chunk = $allowed_db[$i];
86 unset($i, $max_position, $chunk);
89 if (preg_match('@' .$pattern . '@i', $db, $matches)) {
90 if ($matches[0] == $db) {
91 $is_create_table_priv = TRUE;
93 //TODO: maybe receive in $allowed_db also the db names
94 // on which we cannot CREATE, and check them
95 // in this foreach, because if a user is allowed to CREATE
96 // on db foo% but forbidden on db foobar, he should not
97 // see the Create table dialog
102 unset($i, $max_position, $chunk, $pattern);
105 <form method
="post" action
="tbl_create.php"
106 onsubmit
="return (emptyFormElements(this, 'table') && checkFormElementInRange(this, 'num_fields', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidFieldCount']); ?>', 1))">
110 if ($GLOBALS['cfg']['PropertiesIconic']) {
111 echo '<img class="icon" src="' . $pmaThemeImage . 'b_newtbl.png" width="16" height="16" alt="" />';
113 echo sprintf($strCreateNewTable, PMA_getDbLink());
116 <?php
if ($is_create_table_priv) { ?
>
117 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
118 <div
class="formelement">
119 <?php
echo $strName; ?
>:
120 <input type
="text" name
="table" maxlength
="64" size
="30" />
122 <div
class="formelement">
123 <?php
echo $strNumberOfFields; ?
>:
124 <input type
="text" name
="num_fields" size
="2" />
126 <div
class="clearfloat"></div
>
128 <fieldset
class="tblFooters">
129 <input type
="submit" value
="<?php echo $strGo; ?>" />
131 <div
class="error"><?php
echo $strNoPrivileges; ?
></div
>
132 <?php
} // end if else ?>