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