home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / display_create_table.lib.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  4.5 KB  |  135 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  * Displays form for creating a table (if user has privileges for that)
  5.  *
  6.  * @version $Id: display_create_table.lib.php 11326 2008-06-17 21:32:48Z lem9 $
  7.  */
  8. if (! defined('PHPMYADMIN')) {
  9.     exit;
  10. }
  11.  
  12. /**
  13.  *
  14.  */
  15. require_once './libraries/check_user_privileges.lib.php';
  16.  
  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
  24. //
  25. // Note: in this case we could even skip the following "foreach" logic
  26.  
  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
  34. // on MySQL 5.0.18.
  35.  
  36. $is_create_table_priv = true;
  37.  
  38. /*
  39. if (PMA_MYSQL_INT_VERSION >= 40100) {
  40.     $is_create_table_priv = false;
  41. } else {
  42.     $is_create_table_priv = true;
  43. }
  44.  
  45. foreach ($dbs_where_create_table_allowed as $allowed_db) {
  46.  
  47.     // if we find the exact db name, we stop here
  48.     if ($allowed_db == $db) {
  49.         $is_create_table_priv = TRUE;
  50.         break;
  51.     }
  52.  
  53.     // '*' indicates a global CREATE priv
  54.     if ($allowed_db == '*') {
  55.         $is_create_table_priv = TRUE;
  56.         break;
  57.     }
  58.  
  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;
  63.         $i = 0;
  64.         $pattern = '';
  65.         while ($i <= $max_position) {
  66.             if ($allowed_db[$i] == '\\'){
  67.                 if ($i < $max_position - 1 && $allowed_db[$i+1] == '_'){
  68.                     $chunk = '_';
  69.                     $i++;
  70.                 } elseif ($i < $max_position - 1 && $allowed_db[$i+1] == '%'){
  71.                     $chunk = '%';
  72.                     $i++;
  73.                 } else {
  74.                     $chunk = $allowed_db[$i];
  75.                 }
  76.             } elseif ($allowed_db[$i] == '_'){
  77.                 $chunk = '.';
  78.             } elseif ($allowed_db[$i] == '%'){
  79.                 $chunk = '(.)*';
  80.             } else {
  81.                 $chunk = $allowed_db[$i];
  82.             }
  83.             $pattern .= $chunk;
  84.             $i++;
  85.         } // end while
  86.         unset($i, $max_position, $chunk);
  87.  
  88.         $matches = '';
  89.         if (preg_match('@' .$pattern . '@i', $db, $matches)) {
  90.             if ($matches[0] == $db) {
  91.                 $is_create_table_priv = TRUE;
  92.                 break;
  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
  98.             }
  99.         }
  100.     }
  101. } // end foreach
  102. unset($i, $max_position, $chunk, $pattern);
  103. */
  104. ?>
  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))">
  107. <fieldset>
  108.     <legend>
  109. <?php
  110. if ($GLOBALS['cfg']['PropertiesIconic']) {
  111.     echo '<img class="icon" src="' . $pmaThemeImage . 'b_newtbl.png" width="16" height="16" alt="" />';
  112. }
  113. echo sprintf($strCreateNewTable, PMA_getDbLink());
  114. ?>
  115.     </legend>
  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" />
  121.     </div>
  122.     <div class="formelement">
  123.         <?php echo $strNumberOfFields; ?>:
  124.         <input type="text" name="num_fields" size="2" />
  125.     </div>
  126.     <div class="clearfloat"></div>
  127. </fieldset>
  128. <fieldset class="tblFooters">
  129.     <input type="submit" value="<?php echo $strGo; ?>" />
  130. <?php } else { ?>
  131.     <div class="error"><?php echo $strNoPrivileges; ?></div>
  132. <?php } // end if else ?>
  133. </fieldset>
  134. </form>
  135.