[ Index ]
 

Code source de phpMyAdmin 2.10.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/ -> tbl_change.php (source)

   1  <?php
   2  /**
   3   * vim: expandtab sw=4 ts=4 sts=4:
   4   * @version $Id: tbl_change.php 10144 2007-03-20 11:22:31Z cybot_tm $
   5   */
   6  
   7  /**
   8   * Gets the variables sent or posted to this script and displays the header
   9   */
  10  require_once  './libraries/common.lib.php';
  11  
  12  /**
  13   * Sets global variables.
  14   * Here it's better to use a if, instead of the '?' operator
  15   * to avoid setting a variable to '' when it's not present in $_REQUEST
  16   */
  17  if (isset($_REQUEST['pos'])) {
  18      $pos =  $_REQUEST['pos'];
  19  }
  20  if (isset($_REQUEST['session_max_rows'])) {
  21      $session_max_rows = $_REQUEST['session_max_rows'];
  22  }
  23  if (isset($_REQUEST['disp_direction'])) {
  24      $disp_direction = $_REQUEST['disp_direction'];
  25  }
  26  if (isset($_REQUEST['repeat_cells'])) {
  27      $repeat_cells = $_REQUEST['repeat_cells'];
  28  }
  29  if (isset($_REQUEST['dontlimitchars'])) {
  30      $dontlimitchars = $_REQUEST['dontlimitchars'];
  31  }
  32  if (isset($_REQUEST['primary_key'])) {
  33      $primary_key = $_REQUEST['primary_key'];
  34  }
  35  if (isset($_REQUEST['sql_query'])) {
  36      $sql_query = $_REQUEST['sql_query'];
  37  }
  38  if (isset($_REQUEST['ShowFunctionFields'])) {
  39      $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
  40  }
  41  
  42  
  43  $js_to_run = 'tbl_change.js';
  44  require_once  './libraries/header.inc.php';
  45  require_once  './libraries/relation.lib.php'; // foreign keys
  46  require_once  './libraries/file_listing.php'; // file listing
  47  
  48  
  49  /**
  50   * Displays the query submitted and its result
  51   */
  52  if (! empty($disp_message)) {
  53      if (! isset($disp_query)) {
  54          $disp_query     = null;
  55      }
  56      PMA_showMessage($disp_message, $disp_query);
  57  }
  58  
  59  
  60  /**
  61   * Defines the url to return to in case of error in a sql statement
  62   * (at this point, $goto might be set but empty)
  63   */
  64  if (empty($goto)) {
  65      $goto    = 'db_sql.php';
  66  }
  67  /**
  68   * @todo check if we could replace by "db_|tbl_"
  69   */
  70  if (!preg_match('@^(db|tbl)_@', $goto)) {
  71      $err_url = $goto . "?" . PMA_generate_common_url($db) . "&amp;sql_query=" . urlencode($sql_query);
  72  } else {
  73      $err_url = $goto . '?'
  74               . PMA_generate_common_url($db)
  75               . ((preg_match('@^(tbl_)@', $goto)) ? '&amp;table=' . urlencode($table) : '');
  76  }
  77  
  78  
  79  /**
  80   * Ensures db and table are valid, else moves to the "parent" script
  81   */
  82  require_once  './libraries/db_table_exists.lib.php';
  83  
  84  
  85  /**
  86   * Sets parameters for links
  87   */
  88  $url_query = PMA_generate_common_url($db, $table)
  89             . '&amp;goto=tbl_sql.php';
  90  
  91  require_once  './libraries/tbl_info.inc.php';
  92  
  93  /* Get comments */
  94  
  95  $comments_map = array();
  96  
  97  if ($GLOBALS['cfg']['ShowPropertyComments']) {
  98      require_once  './libraries/relation.lib.php';
  99      require_once  './libraries/transformations.lib.php';
 100  
 101      $cfgRelation = PMA_getRelationsParam();
 102  
 103      if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
 104          $comments_map = PMA_getComments($db, $table);
 105      }
 106  }
 107  
 108  /**
 109   * Displays top menu links
 110   */
 111  require_once  './libraries/tbl_links.inc.php';
 112  
 113  
 114  /**
 115   * Get the analysis of SHOW CREATE TABLE for this table
 116   */
 117  $show_create_table = PMA_DBI_fetch_value(
 118          'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
 119          0, 1 );
 120  $analyzed_sql = PMA_SQP_analyze( PMA_SQP_parse( $show_create_table ) );
 121  unset($show_create_table);
 122  
 123  /**
 124   * Get the list of the fields of the current table
 125   */
 126  PMA_DBI_select_db($db);
 127  $table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
 128  if (isset($primary_key)) {
 129      if (is_array($primary_key)) {
 130          $primary_key_array = $primary_key;
 131      } else {
 132          $primary_key_array = array(0 => $primary_key);
 133      }
 134  
 135      $row = array();
 136      $result = array();
 137      foreach ($primary_key_array as $rowcount => $primary_key) {
 138          $local_query             = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';';
 139          $result[$rowcount]       = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
 140          $row[$rowcount]          = PMA_DBI_fetch_assoc($result[$rowcount]);
 141          $primary_keys[$rowcount] = str_replace('\\', '\\\\', $primary_key);
 142  
 143          // No row returned
 144          if (!$row[$rowcount]) {
 145              unset($row[$rowcount], $primary_key_array[$rowcount]);
 146              PMA_showMessage($strEmptyResultSet, $local_query);
 147              echo "\n";
 148              require_once  './libraries/footer.inc.php';
 149          } // end if (no record returned)
 150      }
 151  } else {
 152      $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
 153      unset($row);
 154  }
 155  
 156  // <markus@noga.de>
 157  // retrieve keys into foreign fields, if any
 158  $cfgRelation = PMA_getRelationsParam();
 159  $foreigners  = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
 160  
 161  
 162  /**
 163   * Displays the form
 164   */
 165  // loic1: autocomplete feature of IE kills the "onchange" event handler and it
 166  //        must be replaced by the "onpropertychange" one in this case
 167  $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5)
 168                   ? 'onpropertychange'
 169                   : 'onchange';
 170  // Had to put the URI because when hosted on an https server,
 171  // some browsers send wrongly this form to the http server.
 172  ?>
 173  
 174  <?php if ($cfg['CtrlArrowsMoving']) { ?>
 175  <!-- Set on key handler for moving using by Ctrl+arrows -->
 176  <script src="./js/keyhandler.js" type="text/javascript" language="javascript"></script>
 177  <script type="text/javascript" language="javascript">
 178  //<![CDATA[
 179  var switch_movement = 0;
 180  document.onkeydown = onKeyDownArrowsHandler;
 181  //]]>
 182  </script>
 183  <?php } ?>
 184  
 185  <!-- Change table properties form -->
 186  <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
 187      <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
 188      <input type="hidden" name="goto" value="<?php echo htmlspecialchars($goto); ?>" />
 189      <input type="hidden" name="pos" value="<?php echo isset($pos) ? $pos : 0; ?>" />
 190      <input type="hidden" name="session_max_rows" value="<?php echo isset($session_max_rows) ? $session_max_rows : ''; ?>" />
 191      <input type="hidden" name="disp_direction" value="<?php echo isset($disp_direction) ? $disp_direction : ''; ?>" />
 192      <input type="hidden" name="repeat_cells" value="<?php echo isset($repeat_cells) ? $repeat_cells : ''; ?>" />
 193      <input type="hidden" name="dontlimitchars" value="<?php echo (isset($dontlimitchars) ? $dontlimitchars : 0); ?>" />
 194      <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
 195      <input type="hidden" name="sql_query" value="<?php echo isset($sql_query) ? htmlspecialchars($sql_query) : ''; ?>" />
 196  <?php
 197  if (isset($primary_key_array)) {
 198      foreach ($primary_key_array as $primary_key) {
 199          ?>
 200      <input type="hidden" name="primary_key[]" value="<?php echo htmlspecialchars(trim($primary_key)); ?>" />
 201  <?php
 202      }
 203  }
 204  echo "\n";
 205  
 206  if ($cfg['PropertiesIconic'] == true) {
 207      // We need to copy the value or else the == 'both' check will always return true
 208      $propicon = (string)$cfg['PropertiesIconic'];
 209  
 210      if ($propicon == 'both') {
 211          $iconic_spacer = '<div class="nowrap">';
 212      } else {
 213          $iconic_spacer = '';
 214      }
 215  
 216      $titles['Browse']     = $iconic_spacer . '<img width="16" height="16" src="' . $pmaThemeImage . 'b_browse.png" alt="' . $strBrowseForeignValues . '" title="' . $strBrowseForeignValues . '" border="0" />';
 217  
 218      if ($propicon == 'both') {
 219          $titles['Browse']        .= '&nbsp;' . $strBrowseForeignValues . '</div>';
 220      }
 221  } else {
 222      $titles['Browse']        = $strBrowseForeignValues;
 223  }
 224  
 225  // Set if we passed the first timestamp field
 226  $timestamp_seen = 0;
 227  $fields_cnt     = PMA_DBI_num_rows($table_def);
 228  
 229  // Set a flag here because the 'if' would not be valid in the loop
 230  // if we set a value in some field
 231  $insert_mode = (!isset($row) ? TRUE : FALSE);
 232  if ($insert_mode) {
 233      $loop_array  = array();
 234      for ($i = 0; $i < $cfg['InsertRows']; $i++) {
 235          $loop_array[] = FALSE;
 236      }
 237  } else {
 238      $loop_array  = $row;
 239  }
 240  
 241  while ($trow = PMA_DBI_fetch_assoc($table_def)) {
 242      $trow_table_def[] = $trow;
 243  }
 244  
 245  $tabindex = 0;
 246  $tabindex_for_function = +1000;
 247  $tabindex_for_null     = +2000;
 248  $tabindex_for_value    = 0;
 249  $o_rows   = 0;
 250  $biggest_max_file_size = 0;
 251  
 252  // user can toggle the display of Function column
 253  // (currently does not work for multi-edits)
 254  $url_params['db'] = $db;
 255  $url_params['table'] = $table;
 256  if (isset($primary_key)) {
 257      $url_params['primary_key'] = trim($primary_key);
 258  }
 259  if (isset($sql_query)) {
 260      $url_params['sql_query'] = $sql_query;
 261  }
 262  
 263  if (! $cfg['ShowFunctionFields']) {
 264      $this_url_params = array_merge($url_params,
 265          array('ShowFunctionFields' => 1));
 266      echo $strShow . ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . $strFunction . '</a>' . "\n";
 267  }
 268  
 269  foreach ($loop_array as $vrowcount => $vrow) {
 270      if ($vrow === FALSE) {
 271          unset($vrow);
 272      }
 273  
 274      if ($insert_mode) {
 275          $jsvkey = $vrowcount;
 276          $browse_foreigners_uri = '&amp;pk=' . $vrowcount;
 277      } else {
 278          $jsvkey = htmlspecialchars(trim($primary_keys[$vrowcount]));
 279          $browse_foreigners_uri = '&amp;pk=' . urlencode(trim($primary_keys[$vrowcount]));
 280      }
 281      $vkey = '[multi_edit][' . $jsvkey . ']';
 282  
 283      $vresult = (isset($result) && is_array($result) && isset($result[$vrowcount]) ? $result[$vrowcount] : $result);
 284      if ($insert_mode && $vrowcount > 0) {
 285          echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $vrowcount . '" id="insert_ignore_check_' . $vrowcount . '" />';
 286          echo '<label for="insert_ignore_check_' . $vrowcount . '">' . $strIgnore . '</label><br />' . "\n";
 287      }
 288  ?>
 289      <table>
 290          <tr>
 291              <th><?php echo $strField; ?></th>
 292              <th><?php echo $strType; ?></th>
 293  <?php
 294      if ($cfg['ShowFunctionFields']) {
 295          $this_url_params = array_merge($url_params,
 296              array('ShowFunctionFields' => 0));
 297          echo '          <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . $strHide . '">' . $strFunction . '</a></th>' . "\n";
 298      }
 299  ?>
 300              <th><?php echo $strNull; ?></th>
 301              <th><?php echo $strValue; ?></th>
 302          </tr>
 303  <?php
 304  
 305      // garvin: For looping on multiple rows, we need to reset any variable used inside the loop to indicate sth.
 306      $timestamp_seen = 0;
 307      unset($first_timestamp);
 308  
 309      // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
 310      $m_rows = $o_rows + 1;
 311  
 312      $odd_row = true;
 313      for ($i = 0; $i < $fields_cnt; $i++) {
 314          // Display the submit button after every 15 lines --swix
 315          // (wanted to use an <a href="#bottom"> and <a name> instead,
 316          // but it didn't worked because of the <base href>)
 317  
 318          if ((($o_rows * $fields_cnt + $i) % 15 == 0) && ($i + $o_rows != 0)) {
 319              ?>
 320          <tr>
 321              <th colspan="5" align="right" class="tblFooters">
 322                  <input type="submit" value="<?php echo $strGo; ?>" />&nbsp;
 323              </th>
 324          </tr>
 325              <?php
 326          } // end if
 327          echo "\n";
 328  
 329          $row_table_def   = $trow_table_def[$i];
 330          $row_table_def['True_Type'] = preg_replace('@\(.*@s', '', $row_table_def['Type']);
 331  
 332          $field      = $row_table_def['Field'];
 333          $field_html = htmlspecialchars($field);
 334          $field_md5  = md5($field);
 335  
 336          $unnillify_trigger = $chg_evt_handler . "=\"return unNullify('" . PMA_escapeJsString($field_html) . "', '" . PMA_escapeJsString($jsvkey) . "')\"";
 337          $field_name_appendix =  $vkey . '[' . $field_html . ']';
 338          $field_name_appendix_md5 = $field_md5 . $vkey . '[]';
 339  
 340  
 341          // removed previous PHP3-workaround that caused a problem with
 342          // field names like '000'
 343          //$rowfield = $field;
 344  
 345          // d a t e t i m e
 346          //
 347          // loic1: current date should not be set as default if the field is NULL
 348          //        for the current row
 349          // lem9:  but do not put here the current datetime if there is a default
 350          //        value (the real default value will be set in the
 351          //        Default value logic below)
 352  
 353          // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
 354          // $row_table_def['Default'] is not set if it contains NULL:
 355          // Array ( [Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime )
 356          // but, look what we get if we switch to iso: (Default is NULL)
 357          // Array ( [Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime )
 358          // so I force a NULL into it (I don't think it's possible
 359          // to have an empty default value for DATETIME)
 360          // then, the "if" after this one will work
 361          if ($row_table_def['Type'] == 'datetime'
 362              && !isset($row_table_def['Default'])
 363              && isset($row_table_def['Null'])
 364              && $row_table_def['Null'] == 'YES') {
 365              $row_table_def['Default'] = null;
 366          }
 367  
 368          if ($row_table_def['Type'] == 'datetime'
 369              && (!isset($row_table_def['Default']))
 370              && (!is_null($row_table_def['Default']))) {
 371              // INSERT case
 372              if ($insert_mode) {
 373                  if (isset($vrow)) {
 374                      $vrow[$field] = date('Y-m-d H:i:s', time());
 375                  } else {
 376                      $vrow = array($field => date('Y-m-d H:i:s', time()));
 377                  }
 378              }
 379              // UPDATE case with an empty and not NULL value under PHP4
 380              elseif (empty($vrow[$field]) && is_null($vrow[$field])) {
 381                  $vrow[$field] = date('Y-m-d H:i:s', time());
 382              } // end if... elseif...
 383          }
 384          $len             = (preg_match('@float|double@', $row_table_def['Type']))
 385                           ? 100
 386                           : PMA_DBI_field_len($vresult, $i);
 387          $first_timestamp = 0;
 388  
 389          $field_name = $field_html;
 390          if (isset($comments_map[$field])) {
 391              $field_name = '<span style="border-bottom: 1px dashed black;" title="'
 392                  . htmlspecialchars($comments_map[$field]) . '">' . $field_name . '</span>';
 393          }
 394  
 395          ?>
 396          <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
 397              <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($row_table_def['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center"><?php echo $field_name; ?></td>
 398  
 399          <?php
 400          // The type column
 401          $is_binary                  = stristr($row_table_def['Type'], 'binary');
 402          $is_blob                    = stristr($row_table_def['Type'], 'blob');
 403          $is_char                    = stristr($row_table_def['Type'], 'char');
 404          switch ($row_table_def['True_Type']) {
 405              case 'set':
 406                  $type         = 'set';
 407                  $type_nowrap  = '';
 408                  break;
 409              case 'enum':
 410                  $type         = 'enum';
 411                  $type_nowrap  = '';
 412                  break;
 413              case 'timestamp':
 414                  if (!$timestamp_seen) {   // can only occur once per table
 415                      $timestamp_seen  = 1;
 416                      $first_timestamp = 1;
 417                  }
 418                  $type         = $row_table_def['Type'];
 419                  $type_nowrap  = ' nowrap="nowrap"';
 420                  break;
 421  
 422              default:
 423                  $type         = $row_table_def['Type'];
 424                  $type_nowrap  = ' nowrap="nowrap"';
 425                  break;
 426          }
 427          ?>
 428              <td align="center"<?php echo $type_nowrap; ?>>
 429                  <?php echo $type; ?>
 430              </td>
 431  
 432          <?php
 433  
 434          // Prepares the field value
 435          $real_null_value = FALSE;
 436          if (isset($vrow)) {
 437              if (!isset($vrow[$field])
 438                || (function_exists('is_null') && is_null($vrow[$field]))) {
 439                  $real_null_value = TRUE;
 440                  $vrow[$field]   = '';
 441                  $special_chars = '';
 442                  $data          = $vrow[$field];
 443              } else {
 444                  // loic1: special binary "characters"
 445                  if ($is_binary || $is_blob) {
 446                      $vrow[$field] = str_replace("\x00", '\0', $vrow[$field]);
 447                      $vrow[$field] = str_replace("\x08", '\b', $vrow[$field]);
 448                      $vrow[$field] = str_replace("\x0a", '\n', $vrow[$field]);
 449                      $vrow[$field] = str_replace("\x0d", '\r', $vrow[$field]);
 450                      $vrow[$field] = str_replace("\x1a", '\Z', $vrow[$field]);
 451                  } // end if
 452                  $special_chars   = htmlspecialchars($vrow[$field]);
 453                  $data            = $vrow[$field];
 454              } // end if... else...
 455              // loic1: if a timestamp field value is not included in an update
 456              //        statement MySQL auto-update it to the current timestamp
 457              // lem9:  however, things have changed since MySQL 4.1, so
 458              //        it's better to set a fields_prev in this situation
 459              $backup_field  = (PMA_MYSQL_INT_VERSION < 40100 && $row_table_def['True_Type'] == 'timestamp')
 460                             ? ''
 461                             : '<input type="hidden" name="fields_prev' . $field_name_appendix . '" value="' . htmlspecialchars($vrow[$field]) . '" />';
 462          } else {
 463              // loic1: display default values
 464              if (!isset($row_table_def['Default'])) {
 465                  $row_table_def['Default'] = '';
 466                  $real_null_value          = TRUE;
 467                  $data                     = '';
 468              } else {
 469                  $data                     = $row_table_def['Default'];
 470              }
 471              $special_chars = htmlspecialchars($row_table_def['Default']);
 472              $backup_field  = '';
 473          }
 474  
 475          $idindex  = ($o_rows * $fields_cnt) + $i + 1;
 476          $tabindex = (($idindex - 1) * 3) + 1;
 477  
 478          // The function column
 479          // -------------------
 480          // Change by Bernard M. Piller <bernard@bmpsystems.com>
 481          // We don't want binary data to be destroyed
 482          // Note: from the MySQL manual: "BINARY doesn't affect how the column is
 483          //       stored or retrieved" so it does not mean that the contents is
 484          //       binary
 485          if ($cfg['ShowFunctionFields']) {
 486              if (($cfg['ProtectBinary'] && $is_blob && !$is_upload)
 487                  || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
 488                  echo '        <td align="center">' . $strBinary . '</td>' . "\n";
 489              } elseif (strstr($row_table_def['True_Type'], 'enum') || strstr($row_table_def['True_Type'], 'set')) {
 490                  echo '        <td align="center">--</td>' . "\n";
 491              } else {
 492                  ?>
 493              <td>
 494                  <select name="funcs<?php echo $field_name_appendix; ?>" <?php echo $unnillify_trigger; ?> tabindex="<?php echo ($tabindex + $tabindex_for_function); ?>" id="field_<?php echo $idindex; ?>_1">
 495                      <option></option>
 496                  <?php
 497                  $selected     = '';
 498  
 499                  // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
 500                  // or something similar. Then directly look up the entry in the RestrictFunctions array,
 501                  // which will then reveal the available dropdown options
 502                  if (isset($cfg['RestrictFunctions'])
 503                   && isset($cfg['RestrictColumnTypes'])
 504                   && isset($cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])])
 505                   && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]])) {
 506                      $current_func_type  = $cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])];
 507                      $dropdown           = $cfg['RestrictFunctions'][$current_func_type];
 508                      $default_function   = $cfg['DefaultFunctions'][$current_func_type];
 509                  } else {
 510                      $dropdown = array();
 511                      $default_function   = '';
 512                  }
 513  
 514                  $dropdown_built = array();
 515                  $op_spacing_needed = FALSE;
 516                  // garvin: loop on the dropdown array and print all available options for that field.
 517                  $cnt_dropdown = count($dropdown);
 518                  for ($j = 0; $j < $cnt_dropdown; $j++) {
 519                      // Is current function defined as default?
 520                      // For MySQL < 4.1.2, for the first timestamp we set as
 521                      // default function the one defined in config (which
 522                      // should be NOW() ).
 523                      // For MySQL >= 4.1.2, we don't set the default function
 524                      // if there is a default value for the timestamp
 525                      // (not including CURRENT_TIMESTAMP)
 526                      // and the column does not have the
 527                      // ON UPDATE DEFAULT TIMESTAMP attribute.
 528  
 529                      if (PMA_MYSQL_INT_VERSION < 40102
 530                      || (PMA_MYSQL_INT_VERSION >= 40102
 531                        && !($row_table_def['True_Type'] == 'timestamp'
 532                         && !empty($row_table_def['Default'])
 533                         && !isset($analyzed_sql[0]['create_table_fields'][$field]['on_update_current_timestamp'])))) {
 534                      $selected = ($first_timestamp && $dropdown[$j] == $cfg['DefaultFunctions']['first_timestamp'])
 535                                  || (!$first_timestamp && $dropdown[$j] == $default_function)
 536                                ? ' selected="selected"'
 537                                : '';
 538                  }
 539                      echo '                ';
 540                      echo '<option' . $selected . '>' . $dropdown[$j] . '</option>' . "\n";
 541                      $dropdown_built[$dropdown[$j]] = 'TRUE';
 542                      $op_spacing_needed = TRUE;
 543                  }
 544  
 545                  // garvin: For compatibility's sake, do not let out all other functions. Instead
 546                  // print a separator (blank) and then show ALL functions which weren't shown
 547                  // yet.
 548                  $cnt_functions = count($cfg['Functions']);
 549                  for ($j = 0; $j < $cnt_functions; $j++) {
 550                      if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
 551                          // Is current function defined as default?
 552                          $selected = ($first_timestamp && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
 553                                      || (!$first_timestamp && $cfg['Functions'][$j] == $default_function)
 554                                    ? ' selected="selected"'
 555                                    : '';
 556                          if ($op_spacing_needed == TRUE) {
 557                              echo '                ';
 558                              echo '<option value="">--------</option>' . "\n";
 559                              $op_spacing_needed = FALSE;
 560                          }
 561  
 562                          echo '                ';
 563                          echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
 564                      }
 565                  } // end for
 566                  unset($selected);
 567                  ?>
 568                  </select>
 569              </td>
 570                  <?php
 571              }
 572          } // end if ($cfg['ShowFunctionFields'])
 573  
 574  
 575          // The null column
 576          // ---------------
 577          echo '        <td>' . "\n";
 578          if ($row_table_def['Null'] == 'YES') {
 579              echo '            <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
 580              if ($real_null_value && !$first_timestamp) {
 581                  echo ' value="on"';
 582              }
 583              echo ' />' . "\n";
 584  
 585              if (!(($cfg['ProtectBinary'] && $is_blob) || ($cfg['ProtectBinary'] == 'all' && $is_binary)) ) {
 586  
 587                  echo '            <input type="checkbox" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
 588                       . ' name="fields_null' . $field_name_appendix . '"';
 589                  if ($real_null_value && !$first_timestamp) {
 590                      echo ' checked="checked"';
 591                  }
 592                  echo ' id="field_' . ($idindex) . '_2"';
 593                  $onclick         = ' onclick="if (this.checked) {nullify(';
 594                  if (strstr($row_table_def['True_Type'], 'enum')) {
 595                      if (strlen($row_table_def['Type']) > 20) {
 596                          $onclick .= '1, ';
 597                      } else {
 598                          $onclick .= '2, ';
 599                      }
 600                  } elseif (strstr($row_table_def['True_Type'], 'set')) {
 601                      $onclick     .= '3, ';
 602                  } elseif ($foreigners && isset($foreigners[$field])) {
 603                      $onclick     .= '4, ';
 604                  } else {
 605                      $onclick     .= '5, ';
 606                  }
 607                  $onclick         .= '\'' . PMA_escapeJsString($field_html) . '\', \'' . $field_md5 . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
 608                  echo $onclick;
 609              } else {
 610                  echo '            <input type="hidden" name="fields_null' . $field_name_appendix . '"';
 611                  if ($real_null_value && !$first_timestamp) {
 612                      echo ' value="on"';
 613                  }
 614                  echo ' />' . "\n";
 615              }
 616          }
 617          echo '        </td>' . "\n";
 618  
 619          // The value column (depends on type)
 620          // ----------------
 621  
 622          require  './libraries/get_foreign.lib.php';
 623  
 624          if (isset($foreign_link) && $foreign_link == true) {
 625              ?>
 626              <td>
 627              <?php echo $backup_field . "\n"; ?>
 628              <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
 629                  value="foreign" />
 630              <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
 631                  value="" id="field_<?php echo ($idindex); ?>_1" />
 632              <input type="text"   name="field_<?php echo $field_name_appendix_md5; ?>"
 633                  class="textfield" <?php echo $unnillify_trigger; ?>
 634                  tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
 635                  id="field_<?php echo ($idindex); ?>_3"
 636                  value="<?php echo htmlspecialchars($data); ?>" />
 637              <script type="text/javascript" language="javascript">
 638              //<![CDATA[
 639                  document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
 640                  document.writeln(' href="browse_foreigners.php?');
 641                  document.writeln('<?php echo PMA_generate_common_url($db, $table); ?>');
 642                  document.writeln('&amp;field=<?php echo PMA_escapeJsString(urlencode($field) . $browse_foreigners_uri); ?>">');
 643                  document.writeln('<?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
 644              //]]>
 645              </script>
 646              </td>
 647              <?php
 648          } elseif (isset($disp_row) && is_array($disp_row)) {
 649              ?>
 650              <td>
 651              <?php echo $backup_field . "\n"; ?>
 652              <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
 653                  value="foreign" />
 654              <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
 655                  value="" id="field_<?php echo $idindex; ?>_1" />
 656              <select name="field_<?php echo $field_name_appendix_md5; ?>"
 657                  <?php echo $unnillify_trigger; ?>
 658                  tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
 659                  id="field_<?php echo ($idindex); ?>_3">
 660                  <?php echo PMA_foreignDropdown($disp_row, $foreign_field, $foreign_display, $data, $cfg['ForeignKeyMaxLimit']); ?>
 661              </select>
 662              </td>
 663              <?php
 664              unset($disp_row);
 665          } elseif ($cfg['LongtextDoubleTextarea'] && strstr($type, 'longtext')) {
 666              ?>
 667              <td>&nbsp;</td>
 668          </tr>
 669          <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
 670              <td colspan="5" align="right">
 671                  <?php echo $backup_field . "\n"; ?>
 672                  <textarea name="fields<?php echo $field_name_appendix; ?>"
 673                      rows="<?php echo ($cfg['TextareaRows']*2); ?>"
 674                      cols="<?php echo ($cfg['TextareaCols']*2); ?>"
 675                      dir="<?php echo $text_dir; ?>"
 676                      id="field_<?php echo ($idindex); ?>_3"
 677                      <?php echo $unnillify_trigger; ?>
 678                      tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
 679                      ><?php echo $special_chars; ?></textarea>
 680              </td>
 681            <?php
 682          } elseif (strstr($type, 'text')) {
 683              ?>
 684              <td>
 685                  <?php echo $backup_field . "\n"; ?>
 686                  <textarea name="fields<?php echo $field_name_appendix; ?>"
 687                      rows="<?php echo $cfg['TextareaRows']; ?>"
 688                      cols="<?php echo $cfg['TextareaCols']; ?>"
 689                      dir="<?php echo $text_dir; ?>"
 690                      id="field_<?php echo ($idindex); ?>_3"
 691                      <?php echo $unnillify_trigger; ?>
 692                      tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
 693                      ><?php echo $special_chars; ?></textarea>
 694              </td>
 695              <?php
 696              echo "\n";
 697              if (strlen($special_chars) > 32000) {
 698                  echo '        <td>' . $strTextAreaLength . '</td>' . "\n";
 699              }
 700          } elseif ($type == 'enum') {
 701              $enum        = PMA_getEnumSetOptions($row_table_def['Type']);
 702              $enum_cnt    = count($enum);
 703              ?>
 704              <td>
 705                  <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
 706                  <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
 707              <?php
 708              echo "\n" . '            ' . $backup_field;
 709  
 710              // show dropdown or radio depend on length
 711              if (strlen($row_table_def['Type']) > 20) {
 712                  echo "\n";
 713                  ?>
 714                  <select name="field_<?php echo $field_name_appendix_md5; ?>"
 715                      <?php echo $unnillify_trigger; ?>
 716                      tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
 717                      id="field_<?php echo ($idindex); ?>_3">
 718                      <option value=""></option>
 719                  <?php
 720                  echo "\n";
 721  
 722                  for ($j = 0; $j < $enum_cnt; $j++) {
 723                      // Removes automatic MySQL escape format
 724                      $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
 725                      echo '                ';
 726                      //echo '<option value="' . htmlspecialchars($enum_atom) . '"';
 727                      echo '<option value="' . htmlspecialchars($enum_atom) . '"';
 728                      if ($data == $enum_atom
 729                          || ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
 730                              && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
 731                          echo ' selected="selected"';
 732                      }
 733                      echo '>' . htmlspecialchars($enum_atom) . '</option>' . "\n";
 734                  } // end for
 735  
 736                  ?>
 737                  </select>
 738                  <?php
 739              } else {
 740                  echo "\n";
 741                  for ($j = 0; $j < $enum_cnt; $j++) {
 742                      // Removes automatic MySQL escape format
 743                      $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
 744                      echo '            ';
 745                      echo '<input type="radio" name="field_' . $field_name_appendix_md5 . '"';
 746                      echo ' value="' . htmlspecialchars($enum_atom) . '"';
 747                      echo ' id="field_' . ($idindex) . '_3_'  . $j . '"';
 748                      echo ' onclick="';
 749                      echo "if (typeof(document.forms['insertForm'].elements['fields_null"
 750                          . $field_name_appendix . "']) != 'undefined') {document.forms['insertForm'].elements['fields_null"
 751                          . $field_name_appendix . "'].checked = false}";
 752                      echo '"';
 753                      if ($data == $enum_atom
 754                          || ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
 755                              && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
 756                          echo ' checked="checked"';
 757                      }
 758                      echo 'tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
 759                      echo '<label for="field_' . $idindex . '_3_' . $j . '">'
 760                          . htmlspecialchars($enum_atom) . '</label>' . "\n";
 761                  } // end for
 762  
 763              } // end else
 764              echo "\n";
 765              ?>
 766              </td>
 767              <?php
 768              echo "\n";
 769          } elseif ($type == 'set') {
 770              $set = PMA_getEnumSetOptions($row_table_def['Type']);
 771  
 772              if (isset($vset)) {
 773                  unset($vset);
 774              }
 775              for ($vals = explode(',', $data); list($t, $k) = each($vals);) {
 776                  $vset[$k] = 1;
 777              }
 778              $countset = count($set);
 779              $size = min(4, $countset);
 780              ?>
 781              <td>
 782                  <?php echo $backup_field . "\n"; ?>
 783                  <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
 784                  <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
 785                  <select name="field_<?php echo $field_name_appendix_md5; ?>"
 786                      size="<?php echo $size; ?>"
 787                      multiple="multiple" <?php echo $unnillify_trigger; ?>
 788                      tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
 789                      id="field_<?php echo ($idindex); ?>_3">
 790              <?php
 791              echo "\n";
 792              for ($j = 0; $j < $countset; $j++) {
 793                  echo '                ';
 794                  //echo '<option value="'. htmlspecialchars($set[$j]) . '"';
 795                  echo '<option value="'. htmlspecialchars($set[$j]) . '"';
 796                  if (isset($vset[$set[$j]]) && $vset[$set[$j]]) {
 797                      echo ' selected="selected"';
 798                  }
 799                  echo '>' . htmlspecialchars($set[$j]) . '</option>' . "\n";
 800              } // end for
 801              ?>
 802                  </select>
 803              </td>
 804              <?php
 805          }
 806          // Change by Bernard M. Piller <bernard@bmpsystems.com>
 807          // We don't want binary data destroyed
 808          elseif ($is_binary || $is_blob) {
 809              if (($cfg['ProtectBinary'] && $is_blob)
 810                  || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
 811                  echo "\n";
 812                  ?>
 813              <td>
 814                  <?php
 815                      echo $strBinaryDoNotEdit;
 816                      if (isset($data)) {
 817                          $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
 818                          echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
 819                          unset($data_size);
 820                      }
 821                      echo "\n";
 822                  ?>
 823                  <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
 824                  <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
 825                  <?php
 826              } elseif ($is_blob) {
 827                  echo "\n";
 828                  ?>
 829              <td>
 830                  <?php echo $backup_field . "\n"; ?>
 831                  <textarea name="fields<?php echo $field_name_appendix; ?>"
 832                      rows="<?php echo $cfg['TextareaRows']; ?>"
 833                      cols="<?php echo $cfg['TextareaCols']; ?>"
 834                      dir="<?php echo $text_dir; ?>"
 835                      id="field_<?php echo ($idindex); ?>_3"
 836                      <?php echo $unnillify_trigger; ?>
 837                      tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
 838                      ><?php echo $special_chars; ?></textarea>
 839                  <?php
 840  
 841              } else {
 842                  // field size should be at least 4 and max 40
 843                  $fieldsize = min(max($len, 4), 40);
 844                  echo "\n";
 845                  ?>
 846              <td>
 847                  <?php echo $backup_field . "\n"; ?>
 848                  <input type="text" name="fields<?php echo $field_name_appendix; ?>"
 849                      value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
 850                      class="textfield" <?php echo $unnillify_trigger; ?>
 851                      tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
 852                      id="field_<?php echo ($idindex); ?>_3" />
 853                  <?php
 854              } // end if...elseif...else
 855  
 856              // Upload choice (only for BLOBs because the binary
 857              // attribute does not imply binary contents)
 858              // (displayed whatever value the ProtectBinary has)
 859  
 860              if ($is_upload && $is_blob) {
 861                  echo '<br />';
 862                  echo '<input type="file" name="fields_upload_' . $field_html . $vkey . '" class="textfield" id="field_' . $idindex . '_3" size="10" />&nbsp;';
 863  
 864                  // find maximum upload size, based on field type
 865                  /**
 866                   * @todo with functions this is not so easy, as you can basically
 867                   * process any data with function like MD5
 868                   */
 869                  $max_field_sizes = array(
 870                      'tinyblob'   =>        '256',
 871                      'blob'       =>      '65536',
 872                      'mediumblob' =>   '16777216',
 873                      'longblob'   => '4294967296'); // yeah, really
 874  
 875                  $this_field_max_size = $max_upload_size; // from PHP max
 876                  if ($this_field_max_size > $max_field_sizes[$type]) {
 877                     $this_field_max_size = $max_field_sizes[$type];
 878                  }
 879                  echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
 880                  // do not generate here the MAX_FILE_SIZE, because we should
 881                  // put only one in the form to accommodate the biggest field
 882                  if ($this_field_max_size > $biggest_max_file_size) {
 883                      $biggest_max_file_size = $this_field_max_size;
 884                  }
 885              }
 886  
 887              if (!empty($cfg['UploadDir'])) {
 888                  $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
 889                  if ($files === FALSE) {
 890                      echo '        <font color="red">' . $strError . '</font><br />' . "\n";
 891                      echo '        ' . $strWebServerUploadDirectoryError . "\n";
 892                  } elseif (!empty($files)) {
 893                      echo "<br />\n";
 894                      echo '    <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n";
 895                      echo '        <select size="1" name="fields_uploadlocal_' . $field_html . $vkey . '">' . "\n";
 896                      echo '            <option value="" selected="selected"></option>' . "\n";
 897                      echo $files;
 898                      echo '        </select>' . "\n";
 899                  }
 900              } // end if (web-server upload directory)
 901  
 902              echo '</td>';
 903  
 904          } // end elseif ( binary or blob)
 905          else {
 906              // field size should be at least 4 and max 40
 907              $fieldsize = min(max($len, 4), 40);
 908              ?>
 909              <td>
 910              <?php
 911              echo $backup_field . "\n";
 912              if ($is_char && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== FALSE)) {
 913                  echo "\n";
 914                  ?>
 915                  <textarea name="fields<?php echo $field_name_appendix; ?>"
 916                      rows="<?php echo $cfg['CharTextareaRows']; ?>"
 917                      cols="<?php echo $cfg['CharTextareaCols']; ?>"
 918                      dir="<?php echo $text_dir; ?>"
 919                      id="field_<?php echo ($idindex); ?>_3"
 920                      <?php echo $unnillify_trigger; ?>
 921                      tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
 922                      ><?php echo $special_chars; ?></textarea>
 923                  <?php
 924              } else {
 925                  ?>
 926                  <input type="text" name="fields<?php echo $field_name_appendix; ?>"
 927                      value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
 928                      class="textfield" <?php echo $unnillify_trigger; ?>
 929                      tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
 930                      id="field_<?php echo ($idindex); ?>_3" />
 931                  <?php
 932                  if ($row_table_def['Extra'] == 'auto_increment') {
 933                      ?>
 934                      <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
 935                      <?php
 936                  } // end if
 937                  if (substr($type, 0, 9) == 'timestamp') {
 938                      ?>
 939                      <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
 940                      <?php
 941                  }
 942                  if ($type == 'date' || $type == 'datetime' || substr($type, 0, 9) == 'timestamp') {
 943                      ?>
 944                      <script type="text/javascript" language="javascript">
 945                      //<![CDATA[
 946                      document.write('<a title="<?php echo $strCalendar;?>" href="javascript:openCalendar(\'<?php echo PMA_generate_common_url();?>\', \'insertForm\', \'field_<?php echo ($idindex); ?>_3\', \'<?php echo (PMA_MYSQL_INT_VERSION >= 40100 && substr($type, 0, 9) == 'timestamp') ? 'datetime' : substr($type, 0, 9); ?>\')"><img class="calendar" src="<?php echo $pmaThemeImage; ?>b_calendar.png" alt="<?php echo $strCalendar; ?>"/></a>');
 947                      //]]>
 948                      </script>
 949                      <?php
 950                  }
 951              }
 952              ?>
 953              </td>
 954              <?php
 955          }
 956          ?>
 957          </tr>
 958          <?php
 959          $odd_row = !$odd_row;
 960      } // end for
 961      $o_rows++;
 962      echo '  </table><br />';
 963  } // end foreach on multi-edit
 964  ?>
 965      <br />
 966  
 967      <table border="0" cellpadding="5" cellspacing="0">
 968      <tr>
 969          <td valign="middle" nowrap="nowrap">
 970              <select name="submit_type" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
 971  <?php
 972  if (isset($primary_key)) {
 973      ?>
 974                  <option value="<?php echo $strSave; ?>"><?php echo $strSave; ?></option>
 975      <?php
 976  }
 977      ?>
 978                  <option value="<?php echo $strInsertAsNewRow; ?>"><?php echo $strInsertAsNewRow; ?></option>
 979              </select>
 980      <?php
 981  echo "\n";
 982  
 983  if (!isset($after_insert)) {
 984      $after_insert = 'back';
 985  }
 986  ?>
 987          </td>
 988          <td valign="middle">
 989              &nbsp;&nbsp;&nbsp;<b><?php echo $strAndThen; ?></b>&nbsp;&nbsp;&nbsp;
 990          </td>
 991          <td valign="middle" nowrap="nowrap">
 992              <select name="after_insert">
 993                  <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertBack; ?></option>
 994                  <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNewInsert; ?></option>
 995  <?php
 996  if (isset($primary_key)) {
 997      ?>
 998                  <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertSame; ?></option>
 999      <?php
1000      // If we have just numeric primary key, we can also edit next
1001      // in 2.8.2, we were looking for `field_name` = numeric_value
1002      //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) {
1003      // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1004      if (preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $primary_key)) {
1005          ?>
1006                  <option value="edit_next"><?php echo $strAfterInsertNext; ?></option>
1007          <?php
1008      }
1009  }
1010  ?>
1011              </select>
1012          </td>
1013      </tr>
1014  
1015      <tr>
1016          <td>
1017  <?php echo PMA_showHint($strUseTabKey); ?>
1018          </td>
1019          <td colspan="3" align="right" valign="middle">
1020              <input type="submit" value="<?php echo $strGo; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1021              <input type="reset" value="<?php echo $strReset; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1022          </td>
1023      </tr>
1024      </table>
1025      <?php if ($biggest_max_file_size > 0) {
1026              echo '        ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1027            } ?>
1028  
1029  </form>
1030  
1031  <?php
1032  /**
1033   * Displays the footer
1034   */
1035  require_once  './libraries/footer.inc.php';
1036  ?>


Généré le : Mon Nov 26 15:18:20 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics