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