home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / tbl_change.php < prev    next >
Encoding:
PHP Script  |  2004-06-06  |  39.7 KB  |  849 lines

  1. <?php
  2. /* $Id: tbl_change.php,v 2.10.2.3 2004/06/07 10:57:59 rabus Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * Get the variables sent or posted to this script and displays the header
  8.  */
  9. require_once('./libraries/grab_globals.lib.php');
  10. $js_to_run = 'tbl_change.js';
  11. require_once('./header.inc.php');
  12. require_once('./libraries/relation.lib.php'); // foreign keys
  13.  
  14.  
  15. /**
  16.  * Displays the query submitted and its result
  17.  */
  18. if (!empty($disp_message)) {
  19.     if (isset($goto)) {
  20.         $goto_cpy      = $goto;
  21.         $goto          = 'tbl_properties.php?'
  22.                        . PMA_generate_common_url($db, $table)
  23.                        . '&$show_query=1'
  24.                        . '&sql_query=' . (isset($disp_query) ? urlencode($disp_query) : '');
  25.     } else {
  26.         $show_query = '1';
  27.     }
  28.     if (isset($sql_query)) {
  29.         $sql_query_cpy = $sql_query;
  30.         unset($sql_query);
  31.     }
  32.     if (isset($disp_query)) {
  33.         $sql_query     = $disp_query;
  34.     }
  35.     PMA_showMessage($disp_message);
  36.     if (isset($goto_cpy)) {
  37.         $goto          = $goto_cpy;
  38.         unset($goto_cpy);
  39.     }
  40.     if (isset($sql_query_cpy)) {
  41.         $sql_query     = $sql_query_cpy;
  42.         unset($sql_query_cpy);
  43.     }
  44. }
  45.  
  46.  
  47. /**
  48.  * Defines the url to return to in case of error in a sql statement
  49.  */
  50. if (!isset($goto)) {
  51.     $goto    = 'db_details.php';
  52. }
  53. if (!preg_match('@^(db_details|tbl_properties|tbl_select)@', $goto)) {
  54.     $err_url = $goto . "?" . PMA_generate_common_url($db) . "&sql_query=" . urlencode($sql_query);
  55. } else {
  56.     $err_url = $goto . '?'
  57.              . PMA_generate_common_url($db)
  58.              . ((preg_match('@^(tbl_properties|tbl_select)@', $goto)) ? '&table=' . urlencode($table) : '');
  59. }
  60.  
  61.  
  62. /**
  63.  * Ensures db and table are valid, else moves to the "parent" script
  64.  */
  65. require('./libraries/db_table_exists.lib.php');
  66.  
  67.  
  68. /**
  69.  * Sets parameters for links and displays top menu
  70.  */
  71. $url_query = PMA_generate_common_url($db, $table)
  72.            . '&goto=tbl_properties.php';
  73.  
  74. require('./tbl_properties_table_info.php');
  75. echo '<br />';
  76.  
  77.  
  78. /**
  79.  * Get the list of the fields of the current table
  80.  */
  81. PMA_mysql_select_db($db);
  82. $table_def = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote($table));
  83. if (isset($primary_key)) {
  84.     if (is_array($primary_key)) {
  85.         $primary_key_array = $primary_key;
  86.     } else {
  87.         $primary_key_array = array(0 => $primary_key);
  88.     }
  89.  
  90.     $row = array();
  91.     $result = array();
  92.     foreach($primary_key_array AS $rowcount => $primary_key) {
  93.         $local_query             = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key;
  94.         $result[$rowcount]       = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  95.         $row[$rowcount]          = PMA_mysql_fetch_array($result[$rowcount]);
  96.         $primary_keys[$rowcount] = $primary_key;
  97.     
  98.         // No row returned
  99.         if (!$row[$rowcount]) {
  100.             unset($row[$rowcount]);
  101.             unset($primary_key_array[$rowcount]);
  102.             $goto_cpy          = $goto;
  103.             $goto              = 'tbl_properties.php?'
  104.                                . PMA_generate_common_url($db, $table)
  105.                                . '&$show_query=1'
  106.                                . '&sql_query=' . urlencode($local_query);
  107.             if (isset($sql_query)) {
  108.                 $sql_query_cpy = $sql_query;
  109.                 unset($sql_query);
  110.             }
  111.             $sql_query         = $local_query;
  112.             PMA_showMessage($strEmptyResultSet);
  113.             $goto              = $goto_cpy;
  114.             unset($goto_cpy);
  115.             if (isset($sql_query_cpy)) {
  116.                 $sql_query    = $sql_query_cpy;
  117.                 unset($sql_query_cpy);
  118.             }
  119.         } // end if (no record returned)
  120.     }
  121. } else {
  122.     $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1';
  123.     $result      = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  124.     unset($row);
  125. }
  126.  
  127. // <markus@noga.de>
  128. // retrieve keys into foreign fields, if any
  129. $cfgRelation = PMA_getRelationsParam();
  130. $foreigners  = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
  131.  
  132.  
  133. /**
  134.  * Displays the form
  135.  */
  136. // loic1: autocomplete feature of IE kills the "onchange" event handler and it
  137. //        must be replaced by the "onpropertychange" one in this case
  138. $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5)
  139.                  ? 'onpropertychange'
  140.                  : 'onchange';
  141. // Had to put the URI because when hosted on an https server,
  142. // some browsers send wrongly this form to the http server.
  143. ?>
  144.  
  145. <?php if ($cfg['CtrlArrowsMoving']) { ?>
  146. <!-- Set on key handler for moving using by Ctrl+arrows -->
  147. <script type="text/javascript" language="javascript">
  148. <!--
  149. document.onkeydown = onKeyDownArrowsHandler;
  150. // -->
  151. </script>
  152. <?php } ?>
  153.  
  154. <!-- Change table properties form -->
  155. <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) echo ' enctype="multipart/form-data"'; ?>>
  156.     <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  157.     <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  158.     <input type="hidden" name="pos" value="<?php echo isset($pos) ? $pos : 0; ?>" />
  159.     <input type="hidden" name="session_max_rows" value="<?php echo isset($session_max_rows) ? $session_max_rows : ''; ?>" />
  160.     <input type="hidden" name="disp_direction" value="<?php echo isset($disp_direction) ? $disp_direction : ''; ?>" />
  161.     <input type="hidden" name="repeat_cells" value="<?php echo isset($repeat_cells) ? $repeat_cells : ''; ?>" />
  162.     <input type="hidden" name="dontlimitchars" value="<?php echo (isset($dontlimitchars) ? $dontlimitchars : 0); ?>" />
  163.     <input type="hidden" name="err_url" value="<?php echo urlencode($err_url); ?>" />
  164.     <input type="hidden" name="sql_query" value="<?php echo isset($sql_query) ? urlencode($sql_query) : ''; ?>" />
  165. <?php
  166. if (isset($primary_key_array)) {
  167.     foreach($primary_key_array AS $primary_key) {
  168.         ?>
  169.     <input type="hidden" name="primary_key[]" value="<?php echo urlencode($primary_key); ?>" />
  170. <?php
  171.     }
  172. }
  173. echo "\n";
  174.  
  175. if ($cfg['PropertiesIconic'] == true) {
  176.     // We need to copy the value or else the == 'both' check will always return true
  177.     $propicon = (string)$cfg['PropertiesIconic'];
  178.  
  179.     if ($propicon == 'both') {
  180.         $iconic_spacer = '<nobr>';
  181.     } else {
  182.         $iconic_spacer = '';
  183.     }
  184.  
  185.     $titles['Browse']     = $iconic_spacer . '<img width="12" height="13" src="images/button_browse.png" alt="' . $strBrowseForeignValues . '" title="' . $strBrowseForeignValues . '" border="0" />';
  186.  
  187.     if ($propicon == 'both') {
  188.         $titles['Browse']        .= ' ' . $strBrowseForeignValues . '</nobr>';
  189.     }
  190. } else {
  191.     $titles['Browse']        = $strBrowseForeignValues;
  192. }
  193.  
  194. // Set if we passed the first timestamp field
  195. $timestamp_seen = 0;
  196. $fields_cnt     = mysql_num_rows($table_def);
  197.  
  198. // Set a flag here because the 'if' would not be valid in the loop
  199. // if we set a value in some field
  200. $insert_mode = (!isset($row) ? TRUE : FALSE);
  201. $loop_array  = (isset($row) ? $row : array(0 => FALSE));
  202.  
  203. while ($trow = PMA_mysql_fetch_array($table_def)) {
  204.     $trow_table_def[] = $trow;
  205. }
  206.  
  207. $o_rows = 0;
  208. foreach($loop_array AS $vrowcount => $vrow) {
  209.     if ($vrow === FALSE) {
  210.         unset($vrow);
  211.     }
  212.  
  213.     $vresult = (isset($result) && is_array($result) && isset($result[$vrowcount]) ? $result[$vrowcount] : $result);
  214. ?>
  215.     <table border="<?php echo $cfg['Border']; ?>">
  216.         <tr>
  217.             <th><?php echo $strField; ?></th>
  218.             <th><?php echo $strType; ?></th>
  219. <?php
  220.     if ($cfg['ShowFunctionFields']) {
  221.         echo '          <th>' . $strFunction . '</th>' . "\n";
  222.     }
  223. ?>
  224.             <th><?php echo $strNull; ?></th>
  225.             <th><?php echo $strValue; ?></th>
  226.         </tr>
  227. <?php
  228.  
  229.     if ($insert_mode) {
  230.         $vkey = '';
  231.         $browse_foreigners_uri = '';
  232.     } else {
  233.         $vkey = '[multi_edit][' . urlencode($primary_keys[$vrowcount]) . ']';
  234.         $browse_foreigners_uri = '&pk=' . urlencode($primary_keys[$vrowcount]);
  235.     }
  236.  
  237.     // garvin: For looping on multiple rows, we need to reset any variable used inside the loop to indicate sth.
  238.     $timestamp_seen = 0;
  239.     unset($first_timestamp);
  240.  
  241.     // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
  242.     $m_rows = $o_rows + 1;
  243.     
  244.     for ($i = 0; $i < $fields_cnt; $i++) {
  245.         // Display the submit button after every 15 lines --swix
  246.         // (wanted to use an <a href="#bottom"> and <a name> instead,
  247.         // but it didn't worked because of the <base href>)
  248.     
  249.         if ((($i % 15) == 0) && ($i != 0)) {
  250.             ?>
  251.         <tr>
  252.             <th colspan="5" align="right">
  253.                 <input type="submit" value="<?php echo $strGo; ?>" /> 
  254.             </th>
  255.         </tr>
  256.             <?php
  257.         } // end if
  258.         echo "\n";
  259.     
  260.         $row_table_def   = $trow_table_def[$i];
  261.         $row_table_def['True_Type'] = preg_replace('@\(.*@s', '', $row_table_def['Type']);
  262.     
  263.         $field           = $row_table_def['Field'];
  264.     
  265.         // garvin: possible workaround. If current field is numerical, do not try to
  266.         //  access the result-array with its 'associative' key but with its numerical
  267.         //  represantation.
  268.         if (is_numeric($field)) {
  269.             $rowfield = $i;
  270.         } else {
  271.             $rowfield = $field;
  272.         }
  273.     
  274.         // d a t e t i m e
  275.         //
  276.         // loic1: current date should not be set as default if the field is NULL
  277.         //        for the current row
  278.         // lem9:  but do not put here the current datetime if there is a default
  279.         //        value (the real default value will be set in the
  280.         //        Default value logic below)
  281.         if ($row_table_def['Type'] == 'datetime'
  282.             && (!isset($row_table_def['Default']))
  283.             && (!is_null($row_table_def['Default']))) {
  284.             // INSERT case
  285.             if ($insert_mode) {
  286.                 if (isset($vrow)) {
  287.                     $vrow[$rowfield] = date('Y-m-d H:i:s', time());
  288.                 } else {
  289.                     $vrow = array($rowfield => date('Y-m-d H:i:s', time()));
  290.                 }
  291.             }
  292.             // UPDATE case with an empty and not NULL value under PHP4
  293.             else if (empty($vrow[$rowfield]) && is_null($vrow[$rowfield])) {
  294.                 $vrow[$rowfield] = date('Y-m-d H:i:s', time());
  295.             } // end if... else if...
  296.         }
  297.         $len             = (preg_match('@float|double@', $row_table_def['Type']))
  298.                          ? 100
  299.                          : @mysql_field_len($vresult, $i);
  300.         $first_timestamp = 0;
  301.     
  302.         $bgcolor = ($i % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
  303.         ?>
  304.         <tr>
  305.             <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($row_table_def['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center" bgcolor="<?php echo $bgcolor; ?>"><?php echo htmlspecialchars($field); ?></td>
  306.         <?php
  307.         echo "\n";
  308.     
  309.         // The type column
  310.         $is_binary                  = stristr($row_table_def['Type'], ' binary');
  311.         $is_blob                    = stristr($row_table_def['Type'], 'blob');
  312.         $is_char                    = stristr($row_table_def['Type'], 'char');
  313.         switch ($row_table_def['True_Type']) {
  314.             case 'set':
  315.                 $type         = 'set';
  316.                 $type_nowrap  = '';
  317.                 break;
  318.             case 'enum':
  319.                 $type         = 'enum';
  320.                 $type_nowrap  = '';
  321.                 break;
  322.             case 'timestamp':
  323.                 if (!$timestamp_seen) {   // can only occur once per table
  324.                     $timestamp_seen  = 1;
  325.                     $first_timestamp = 1;
  326.                 }
  327.                 $type         = $row_table_def['Type'];
  328.                 $type_nowrap  = ' nowrap="nowrap"';
  329.                 break;
  330.     
  331.             default:
  332.                 $type         = $row_table_def['Type'];
  333.                 $type_nowrap  = ' nowrap="nowrap"';
  334.                 break;
  335.         }
  336.         ?>
  337.             <td align="center" bgcolor="<?php echo $bgcolor; ?>"<?php echo $type_nowrap; ?>>
  338.                 <?php echo $type; ?>
  339.             </td>
  340.         <?php
  341.         echo "\n";
  342.     
  343.         // Prepares the field value
  344.         $real_null_value = FALSE;
  345.         if (isset($vrow)) {
  346.             if (!isset($vrow[$rowfield])
  347.               || (function_exists('is_null') && is_null($vrow[$rowfield]))) {
  348.                 $real_null_value = TRUE;
  349.                 $vrow[$rowfield]   = '';
  350.                 $special_chars = '';
  351.                 $data          = $vrow[$rowfield];
  352.             } else {
  353.                 // loic1: special binary "characters"
  354.                 if ($is_binary || $is_blob) {
  355.                     $vrow[$rowfield] = str_replace("\x00", '\0', $vrow[$rowfield]);
  356.                     $vrow[$rowfield] = str_replace("\x08", '\b', $vrow[$rowfield]);
  357.                     $vrow[$rowfield] = str_replace("\x0a", '\n', $vrow[$rowfield]);
  358.                     $vrow[$rowfield] = str_replace("\x0d", '\r', $vrow[$rowfield]);
  359.                     $vrow[$rowfield] = str_replace("\x1a", '\Z', $vrow[$rowfield]);
  360.                 } // end if
  361.                 $special_chars   = htmlspecialchars($vrow[$rowfield]);
  362.                 $data            = $vrow[$rowfield];
  363.             } // end if... else...
  364.             // loic1: if a timestamp field value is not included in an update
  365.             //        statement MySQL auto-update it to the current timestamp
  366.             $backup_field  = ($row_table_def['True_Type'] == 'timestamp')
  367.                            ? ''
  368.                            : '<input type="hidden" name="fields_prev' . $vkey . '[' . urlencode($field) . ']" value="' . urlencode($vrow[$rowfield]) . '" />';
  369.         } else {
  370.             // loic1: display default values
  371.             if (!isset($row_table_def['Default'])) {
  372.                 $row_table_def['Default'] = '';
  373.                 $real_null_value          = TRUE;
  374.                 $data                     = '';
  375.                 //$data                     = 'NULL';
  376.             } else {
  377.                 $data                     = $row_table_def['Default'];
  378.             }
  379.             $special_chars = htmlspecialchars($row_table_def['Default']);
  380.             $backup_field  = '';
  381.         }
  382.     
  383.         // The function column
  384.         // -------------------
  385.         // Change by Bernard M. Piller <bernard@bmpsystems.com>
  386.         // We don't want binary data to be destroyed
  387.         // Note: from the MySQL manual: "BINARY doesn't affect how the column is
  388.         //       stored or retrieved" so it does not mean that the contents is
  389.         //       binary
  390.         if ($cfg['ShowFunctionFields']) {
  391.             if (($cfg['ProtectBinary'] && $is_blob)
  392.                 || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
  393.                 echo '        <td align="center" bgcolor="'. $bgcolor . '">' . $strBinary . '</td>' . "\n";
  394.             } else if (strstr($row_table_def['True_Type'], 'enum') || strstr($row_table_def['True_Type'], 'set')) {
  395.                 echo '        <td align="center" bgcolor="'. $bgcolor . '">--</td>' . "\n";
  396.             } else {
  397.                 ?>
  398.             <td bgcolor="<?php echo $bgcolor; ?>">
  399.                 <select name="funcs<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo ($fields_cnt + ($i * $m_rows) + 1); ?>" id="field_<?php echo $i * $m_rows; ?>_1">
  400.                     <option></option>
  401.                 <?php
  402.                 echo "\n";
  403.                 $selected     = '';
  404.     
  405.                 // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
  406.                 // or something similar. Then directly look up the entry in the RestrictFunctions array,
  407.                 // which will then reveal the available dropdown options
  408.                 if (isset($cfg['RestrictFunctions']) && isset($cfg['RestrictColumnTypes']) && isset($cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]) && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]])) {
  409.                     $current_func_type  = $cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])];
  410.                     $dropdown           = $cfg['RestrictFunctions'][$current_func_type];
  411.                     $default_function   = $cfg['DefaultFunctions'][$current_func_type];
  412.                 } else {
  413.                     $dropdown = array();
  414.                 }
  415.     
  416.                 $dropdown_built = array();
  417.                 $op_spacing_needed = FALSE;
  418.     
  419.                 // garvin: loop on the dropdown array and print all available options for that field.
  420.                 $cnt_dropdown = count($dropdown);
  421.                 for ($j = 0; $j < $cnt_dropdown; $j++) {
  422.                     // Is current function defined as default?
  423.                     $selected = ($first_timestamp && $dropdown[$j] == $cfg['DefaultFunctions']['first_timestamp'])
  424.                                 || (!$first_timestamp && $dropdown[$j] == $default_function)
  425.                               ? ' selected="selected"'
  426.                               : '';
  427.                     echo '                ';
  428.                     echo '<option' . $selected . '>' . $dropdown[$j] . '</option>' . "\n";
  429.                     $dropdown_built[$dropdown[$j]] = 'TRUE';
  430.                     $op_spacing_needed = TRUE;
  431.                 }
  432.     
  433.                 // garvin: For compatibility's sake, do not let out all other functions. Instead
  434.                 // print a seperator (blank) and then show ALL functions which weren't shown
  435.                 // yet.
  436.                 $cnt_functions = count($cfg['Functions']);
  437.                 for ($j = 0; $j < $cnt_functions; $j++) {
  438.                     if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
  439.                         // Is current function defined as default?
  440.                         $selected = ($first_timestamp && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
  441.                                     || (!$first_timestamp && $cfg['Functions'][$j] == $default_function)
  442.                                   ? ' selected="selected"'
  443.                                   : '';
  444.                         if ($op_spacing_needed == TRUE) {
  445.                             echo '                ';
  446.                             echo '<option value="">--------</option>' . "\n";
  447.                             $op_spacing_needed = FALSE;
  448.                         }
  449.     
  450.                         echo '                ';
  451.                         echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
  452.                     }
  453.                 } // end for
  454.                 unset($selected);
  455.                 ?>
  456.                 </select>
  457.             </td>
  458.                 <?php
  459.             }
  460.         } // end if ($cfg['ShowFunctionFields'])
  461.         echo "\n";
  462.     
  463.         // The null column
  464.         // ---------------
  465.         echo '        <td bgcolor="' . $bgcolor . '">' . "\n";
  466.         if (!(($cfg['ProtectBinary'] && $is_blob) || ($cfg['ProtectBinary'] == 'all' && $is_binary))
  467.             && $row_table_def['Null'] == 'YES') {
  468.             echo '            <input type="checkbox" tabindex="' . ((2 * $fields_cnt) + ($i * $m_rows) + 1) . '"'
  469.                  . ' name="fields_null' . $vkey . '[' . urlencode($field) . ']"';
  470.             //if ($data == 'NULL' && !$first_timestamp) {
  471.             if ($real_null_value && !$first_timestamp) {
  472.                 echo ' checked="checked"';
  473.             }
  474.             echo ' id="field_' . ($i * $m_rows) . '_2"';
  475.             $onclick         = ' onclick="if (this.checked) {nullify(';
  476.             if (strstr($row_table_def['True_Type'], 'enum')) {
  477.                 if (strlen($row_table_def['Type']) > 20) {
  478.                     $onclick .= '1, ';
  479.                 } else {
  480.                     $onclick .= '2, ';
  481.                 }
  482.             } else if (strstr($row_table_def['True_Type'], 'set')) {
  483.                 $onclick     .= '3, ';
  484.             } else if ($foreigners && isset($foreigners[$field])) {
  485.                 $onclick     .= '4, ';
  486.             } else {
  487.                 $onclick     .= '5, ';
  488.             }
  489.             $onclick         .= '\'' . urlencode($field) . '\', \'' . md5($field) . '\', \'' . $vkey . '\'); this.checked = true}; return true" />' . "\n";
  490.             echo $onclick;
  491.         } else {
  492.             echo '             ' . "\n";
  493.         }
  494.         echo '        </td>' . "\n";
  495.     
  496.         // The value column (depends on type)
  497.         // ----------------
  498.     
  499.         require('./libraries/get_foreign.lib.php');
  500.     
  501.         if (isset($foreign_link) && $foreign_link == true) {
  502.             ?>
  503.             <td bgcolor="<?php echo $bgcolor; ?>">
  504.             <?php echo $backup_field . "\n"; ?>
  505.             <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="foreign" />
  506.             <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" id="field_<?php echo ($i * $m_rows); ?>_1" />
  507.             <input type="text"   name="field_<?php echo md5($field); ?><?php echo $vkey; ?>[]" class="textfield" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" id="field_<?php echo ($i * $mrows); ?>_3" value="<?php echo htmlspecialchars($data); ?>" />
  508.             <script type="text/javascript" language="javascript">
  509.                 document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false" href="browse_foreigners.php?<?php echo PMA_generate_common_url($db, $table); ?>&field=<?php echo urlencode($field) . $browse_foreigners_uri; ?>"><?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
  510.             </script>
  511.             </td>
  512.             <?php
  513.         } else if (isset($disp) && $disp) {
  514.             ?>
  515.             <td bgcolor="<?php echo $bgcolor; ?>">
  516.             <?php echo $backup_field . "\n"; ?>
  517.             <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="foreign" />
  518.             <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" id="field_<?php echo $i; ?>_1" />
  519.             <select name="field_<?php echo md5($field); ?><?php echo $vkey; ?>[]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" id="field_<?php echo ($i * $m_rows); ?>_3">
  520.                 <?php echo PMA_foreignDropdown($disp, $foreign_field, $foreign_display, $data, 100); ?>
  521.             </select>
  522.             </td>
  523.             <?php
  524.             unset($disp);
  525.         }
  526.         else if ($cfg['LongtextDoubleTextarea'] && strstr($type, 'longtext')) {
  527.             ?>
  528.             <td bgcolor="<?php echo $bgcolor; ?>"> </td>
  529.         </tr>
  530.         <tr>
  531.             <td colspan="4" align="right" bgcolor="<?php echo $bgcolor; ?>">
  532.                 <?php echo $backup_field . "\n"; ?>
  533.                 <textarea name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" rows="<?php echo ($cfg['TextareaRows']*2); ?>" cols="<?php echo ($cfg['TextareaCols']*2); ?>" wrap="virtual" dir="<?php echo $text_dir; ?>" id="field_<?php echo ($i * $m_rows); ?>_3"
  534.                     <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>"><?php echo $special_chars; ?></textarea>
  535.             </td>
  536.           <?php
  537.         }
  538.         else if (strstr($type, 'text')) {
  539.             ?>
  540.             <td bgcolor="<?php echo $bgcolor; ?>">
  541.                 <?php echo $backup_field . "\n"; ?>
  542.                 <textarea name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" rows="<?php echo $cfg['TextareaRows']; ?>" cols="<?php echo $cfg['TextareaCols']; ?>" wrap="virtual" dir="<?php echo $text_dir; ?>" id="field_<?php echo ($i * $m_rows); ?>_3"
  543.                     <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>"><?php echo $special_chars; ?></textarea>
  544.             </td>
  545.             <?php
  546.             echo "\n";
  547.             if (strlen($special_chars) > 32000) {
  548.                 echo '        <td bgcolor="' . $bgcolor . '">' . $strTextAreaLength . '</td>' . "\n";
  549.             }
  550.         }
  551.         else if ($type == 'enum') {
  552.             $enum        = PMA_getEnumSetOptions($row_table_def['Type']);
  553.             $enum_cnt    = count($enum);
  554.             ?>
  555.             <td bgcolor="<?php echo $bgcolor; ?>">
  556.                 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="enum" />
  557.                 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" />
  558.             <?php
  559.             echo "\n" . '            ' . $backup_field;
  560.     
  561.             // show dropdown or radio depend on length
  562.             if (strlen($row_table_def['Type']) > 20) {
  563.                 echo "\n";
  564.                 ?>
  565.                 <select name="field_<?php echo md5($field); ?><?php echo $vkey; ?>[]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" id="field_<?php echo ($i * $m_rows); ?>_3">
  566.                     <option value=""></option>
  567.                 <?php
  568.                 echo "\n";
  569.     
  570.                 for ($j = 0; $j < $enum_cnt; $j++) {
  571.                     // Removes automatic MySQL escape format
  572.                     $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
  573.                     echo '                ';
  574.                     //echo '<option value="' . htmlspecialchars($enum_atom) . '"';
  575.                     echo '<option value="' . urlencode($enum_atom) . '"';
  576.                     if ($data == $enum_atom
  577.                         || ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
  578.                             && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
  579.                         echo ' selected="selected"';
  580.                     }
  581.                     echo '>' . htmlspecialchars($enum_atom) . '</option>' . "\n";
  582.                 } // end for
  583.     
  584.                 ?>
  585.                 </select>
  586.                 <?php
  587.             } // end if
  588.             else {
  589.                 echo "\n";
  590.                 for ($j = 0; $j < $enum_cnt; $j++) {
  591.                     // Removes automatic MySQL escape format
  592.                     $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
  593.                     echo '            ';
  594.                     echo '<input type="radio" name="field_' . md5($field) . $vkey . '[]" value="' . urlencode($enum_atom) . '" id="field_' . ($i*$m_rows) . '_3_'  . $j . '" onclick="if (typeof(document.forms[\'insertForm\'].elements[\'fields_null' . str_replace('"', '\"', $vkey) . '[' . urlencode($field) . ']\']) != \'undefined\') {document.forms[\'insertForm\'].elements[\'fields_null' . str_replace('"', '\"', $vkey) . '[' . urlencode($field) .']\'].checked = false}"';
  595.                     if ($data == $enum_atom
  596.                         || ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
  597.                             && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
  598.                         echo ' checked="checked"';
  599.                     }
  600.                     echo 'tabindex="' . (($i * $m_rows) + 1) . '" />' . "\n";
  601.                     echo '            <label for="field_' . ($i * $m_rows) . '_3_' . $j . '">' . htmlspecialchars($enum_atom) . '</label>' . "\n";
  602.                 } // end for
  603.     
  604.             } // end else
  605.             echo "\n";
  606.             ?>
  607.             </td>
  608.             <?php
  609.             echo "\n";
  610.         }
  611.         else if ($type == 'set') {
  612.             $set = PMA_getEnumSetOptions($row_table_def['Type']);
  613.     
  614.             if (isset($vset)) {
  615.                 unset($vset);
  616.             }
  617.             for ($vals = explode(',', $data); list($t, $k) = each($vals);) {
  618.                 $vset[$k] = 1;
  619.             }
  620.             $countset = count($set);
  621.             $size = min(4, $countset);
  622.             ?>
  623.             <td bgcolor="<?php echo $bgcolor; ?>">
  624.                 <?php echo $backup_field . "\n"; ?>
  625.                 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="set" />
  626.                 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" />
  627.                 <select name="field_<?php echo md5($field); ?><?php echo $vkey; ?>[]" size="<?php echo $size; ?>" multiple="multiple" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" id="field_<?php echo ($i * $m_rows); ?>_3">
  628.             <?php
  629.             echo "\n";
  630.             for ($j = 0; $j < $countset; $j++) {
  631.                 echo '                ';
  632.                 //echo '<option value="'. htmlspecialchars($set[$j]) . '"';
  633.                 echo '<option value="'. urlencode($set[$j]) . '"';
  634.                 if (isset($vset[$set[$j]]) && $vset[$set[$j]]) {
  635.                     echo ' selected="selected"';
  636.                 }
  637.                 echo '>' . htmlspecialchars($set[$j]) . '</option>' . "\n";
  638.             } // end for
  639.             ?>
  640.                 </select>
  641.             </td>
  642.             <?php
  643.         }
  644.         // Change by Bernard M. Piller <bernard@bmpsystems.com>
  645.         // We don't want binary data destroyed
  646.         else if ($is_binary || $is_blob) {
  647.             if (($cfg['ProtectBinary'] && $is_blob)
  648.                 || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
  649.                 echo "\n";
  650.                 ?>
  651.             <td bgcolor="<?php echo $bgcolor; ?>">
  652.                 <?php
  653.                     echo $strBinaryDoNotEdit;
  654.                     if (isset($data)) {
  655.                         $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
  656.                         echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
  657.                         unset($data_size);
  658.                     }
  659.                     echo "\n";
  660.                 ?>
  661.                 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="protected" />
  662.                 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" />
  663.                 <?php
  664.             } else if ($is_blob) {
  665.                 echo "\n";
  666.                 ?>
  667.             <td bgcolor="<?php echo $bgcolor; ?>">
  668.                 <?php echo $backup_field . "\n"; ?>
  669.                 <textarea name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" rows="<?php echo $cfg['TextareaRows']; ?>" cols="<?php echo $cfg['TextareaCols']; ?>" wrap="virtual" dir="<?php echo $text_dir; ?>" id="field_<?php echo ($i*$m_rows); ?>_3"
  670.                     <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" ><?php echo $special_chars; ?></textarea>
  671.                 <?php
  672.     
  673.             } else {
  674.                 if ($len < 4) {
  675.                     $fieldsize = $maxlength = 4;
  676.                 } else {
  677.                     $fieldsize = (($len > 40) ? 40 : $len);
  678.                     $maxlength = $len;
  679.                 }
  680.                 echo "\n";
  681.                 ?>
  682.             <td bgcolor="<?php echo $bgcolor; ?>">
  683.                 <?php echo $backup_field . "\n"; ?>
  684.                 <input type="text" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>" maxlength="<?php echo $maxlength; ?>" class="textfield" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" id="field_<?php echo ($i * $m_rows); ?>_3" />
  685.                 <?php
  686.             } // end if...elseif...else
  687.     
  688.             // Upload choice (only for BLOBs because the binary
  689.             // attribute does not imply binary contents)
  690.             // (displayed whatever value the ProtectBinary has)
  691.     
  692.             if ($is_upload && $is_blob) {
  693.                 echo '<input type="file" name="fields_upload_' . urlencode($field) . $vkey . '" class="textfield" id="field_' . ($i * $m_rows) . '_3" size="10" /> ';
  694.  
  695.                 // find maximum upload size, based on field type
  696.                 $max_field_sizes = array(
  697.                     'tinyblob'   =>        '256',
  698.                     'blob'       =>      '65536',
  699.                     'mediumblob' =>   '16777216',
  700.                     'longblob'   => '4294967296'); // yeah, really
  701.  
  702.                 $this_field_max_size = $max_upload_size; // from PHP max
  703.                 if ($this_field_max_size > $max_field_sizes[$type]) {
  704.                    $this_field_max_size = $max_field_sizes[$type];
  705.                 }
  706.                 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
  707.                 echo '                ' . PMA_generateHiddenMaxFileSize($this_field_max_size) . "\n"; 
  708.             }
  709.  
  710.             if (!empty($cfg['UploadDir'])) {
  711.                 if (substr($cfg['UploadDir'], -1) != '/') {
  712.                     $cfg['UploadDir'] .= '/';
  713.                 }
  714.                 if ($handle = @opendir($cfg['UploadDir'])) {
  715.                     $is_first = 0;
  716.                     while ($file = @readdir($handle)) {
  717.                         if (is_file($cfg['UploadDir'] . $file) && !PMA_checkFileExtensions($file, '.sql')) {
  718.                             if ($is_first == 0) {
  719.                                 echo "<br />\n";
  720.                                 echo '    <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ' :<br />' . "\n";
  721.                                 echo '        <select size="1" name="fields_uploadlocal_' . urlencode($field) . $vkey . '">' . "\n";
  722.                                 echo '            <option value="" selected="selected"></option>' . "\n";
  723.                             } // end if (is_first)
  724.                             echo '            <option value="' . htmlspecialchars($file) . '">' . htmlspecialchars($file) . '</option>' . "\n";
  725.                             $is_first++;
  726.                         } // end if (is_file)
  727.                     } // end while
  728.                     if ($is_first > 0) {
  729.                         echo '        </select>' . "\n";
  730.                     } // end if (isfirst > 0)
  731.                     @closedir($handle);
  732.                 } else {
  733.                     echo '        <font color="red">' . $strError . '</font><br />' . "\n";
  734.                     echo '        ' . $strWebServerUploadDirectoryError . "\n";
  735.                 }
  736.             } // end if (web-server upload directory)
  737.     
  738.             echo '</td>';
  739.     
  740.         } // end else if ( binary or blob)
  741.         else {
  742.             // For char or varchar, respect the maximum length (M); for other
  743.             // types (int or float), the length is not a limit on the values that
  744.             // can be entered, so let's be generous (20) (we could also use the
  745.             // real limits for each numeric type)
  746.             // 2004-04-07, it turned out that 20 was not generous enough
  747.             // for the maxlength
  748.             if ($is_char) {
  749.                 $fieldsize = (($len > 40) ? 40 : $len);
  750.                 $maxlength = $len;
  751.             }
  752.             else {
  753.                 $fieldsize = 20;
  754.                 $maxlength = 99;
  755.             } // end if... else...
  756.             echo "\n";
  757.             ?>
  758.             <td bgcolor="<?php echo $bgcolor; ?>">
  759.                 <?php echo $backup_field . "\n"; ?>
  760.             <?php
  761.             if ($is_char && isset($cfg['CharEditing']) && ($cfg['CharEditing'] == 'textarea')) {
  762.                 echo "\n";
  763.                 ?>
  764.                 <textarea name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" rows="<?php echo $cfg['CharTextareaRows']; ?>" cols="<?php echo $cfg['CharTextareaCols']; ?>" wrap="virtual" dir="<?php echo $text_dir; ?>" id="field_<?php echo ($i * $m_rows); ?>_3"
  765.                     <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" ><?php echo $special_chars; ?></textarea>
  766.                 <?php
  767.             } else {
  768.                 echo "\n";
  769.                 ?>
  770.                 <input type="text" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>" maxlength="<?php echo $maxlength; ?>" class="textfield" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" id="field_<?php echo ($i * $m_rows); ?>_3" />
  771.                 <?php
  772.             }
  773.             echo "\n";
  774.             ?>
  775.             </td>
  776.             <?php
  777.         }
  778.         echo "\n";
  779.         ?>
  780.         </tr>
  781.         <?php
  782.     echo "\n";
  783.     } // end for
  784.     $o_rows++;
  785.     echo '  </table><br />';
  786. } // end foreach on multi-edit
  787. ?>
  788.     <br />
  789.  
  790.     <table cellpadding="5">
  791.     <tr>
  792.         <td valign="middle" nowrap="nowrap">
  793. <?php
  794. if (isset($primary_key)) {
  795.     ?>
  796.             <input type="radio" name="submit_type" value="<?php echo $strSave; ?>" id="radio_submit_type_save" checked="checked" tabindex="<?php echo ((3 * $fields_cnt) + 1); ?>" /><label for="radio_submit_type_save"><?php echo $strSave; ?></label><br />
  797.                   <?php echo $strOr; ?><br />
  798.             <input type="radio" name="submit_type" value="<?php echo $strInsertAsNewRow; ?>" id="radio_submit_type_insert_as_new_row" tabindex="<?php echo ((3 * $fields_cnt) + 2); ?>" /><label for="radio_submit_type_insert_as_new_row"><?php echo $strInsertAsNewRow; ?></label>
  799.     <?php
  800. } else {
  801.     echo "\n";
  802.     ?>
  803.             <input type="hidden" name="submit_type" value="<?php echo $strInsertAsNewRow; ?>" />
  804.     <?php
  805.     echo '            ' . $strInsertAsNewRow . "\n";
  806. }
  807. echo "\n";
  808.  
  809. // Defines whether "insert a new row after the current insert" should be
  810. // checked or not (keep this choice sticky)
  811. // but do not check both radios, because Netscape 4.8 would display both checked
  812. if (!empty($disp_message)) {
  813.     $checked_after_insert_new_insert = ' checked="checked"';
  814.     $checked_after_insert_back = '';
  815. } else {
  816.     $checked_after_insert_back = ' checked="checked"';
  817.     $checked_after_insert_new_insert = '';
  818. }
  819. ?>
  820.         </td>
  821.         <td valign="middle">
  822.                <b>-- <?php echo $strAnd; ?> --</b>   
  823.         </td>
  824.         <td valign="middle" nowrap="nowrap">
  825.             <input type="radio" name="after_insert" value="back" id="radio_after_insert_back" <?php echo $checked_after_insert_back; ?> tabindex="<?php echo ((3 * $fields_cnt) + 3); ?>" /><label for="radio_after_insert_back"><?php echo $strAfterInsertBack; ?></label><br />
  826.                   <?php echo $strOr; ?><br />
  827.             <input type="radio" name="after_insert" value="new_insert" id="radio_after_insert_new_insert"<?php echo $checked_after_insert_new_insert; ?> tabindex="<?php echo ((3 * $fields_cnt) + 4); ?>" /><label for="radio_after_insert_new_insert"><?php echo $strAfterInsertNewInsert; ?></label>
  828.         </td>
  829.     </tr>
  830.  
  831.     <tr>
  832.         <td colspan="3" align="right" valign="middle">
  833.             <input type="submit" value="<?php echo $strGo; ?>" tabindex="<?php echo ((3 * $fields_cnt) + 5); ?>" />
  834.             <input type="reset" value="<?php echo $strReset; ?>" tabindex="<?php echo ((3 * $fields_cnt) + 6); ?>" />
  835.         </td>
  836.     </tr>
  837.     </table>
  838.  
  839. </form>
  840.  
  841.  
  842. <?php
  843. /**
  844.  * Displays the footer
  845.  */
  846. echo "\n";
  847. require_once('./footer.inc.php');
  848. ?>
  849.