/**
 * Get HTML for binary and blob column
 *
 * @param array   $column                description of column in given table
 * @param string  $data                  data to edit
 * @param string  $special_chars         special characters
 * @param integer $biggest_max_file_size biggest max file size for uploading
 * @param string  $backup_field          hidden input field
 * @param string  $column_name_appendix  the name attribute
 * @param string  $onChangeClause        onchange clause for fields
 * @param integer $tabindex              tab index
 * @param integer $tabindex_for_value    offset for the values tabindex
 * @param integer $idindex               id index
 * @param string  $text_dir              text direction
 * @param string  $special_chars_encoded replaced char if the string starts
 *                                       with a \r\n pair (0x0d0a) add an extra \n
 * @param string  $vkey                  [multi_edit]['row_id']
 * @param boolean $is_upload             is upload or not
 *
 * @return string                           an html snippet
 */
function PMA_getBinaryAndBlobColumn($column, $data, $special_chars, $biggest_max_file_size, $backup_field, $column_name_appendix, $onChangeClause, $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded, $vkey, $is_upload)
{
    $html_output = '';
    // Add field type : Protected or Hexadecimal
    $fields_type_html = '<input type="hidden" name="fields_type' . $column_name_appendix . '" value="%s" />';
    // Default value : hex
    $fields_type_val = 'hex';
    if ($GLOBALS['cfg']['ProtectBinary'] === 'blob' && $column['is_blob'] || $GLOBALS['cfg']['ProtectBinary'] === 'all' || $GLOBALS['cfg']['ProtectBinary'] === 'noblob' && !$column['is_blob']) {
        $html_output .= __('Binary - do not edit');
        if (isset($data)) {
            $data_size = PMA_Util::formatByteDown(mb_strlen(stripslashes($data)), 3, 1);
            $html_output .= ' (' . $data_size[0] . ' ' . $data_size[1] . ')';
            unset($data_size);
        }
        $fields_type_val = 'protected';
        $html_output .= '<input type="hidden" name="fields' . $column_name_appendix . '" value="" />';
    } elseif ($column['is_blob'] || $column['len'] > $GLOBALS['cfg']['LimitChars']) {
        $html_output .= "\n" . PMA_getTextarea($column, $backup_field, $column_name_appendix, $onChangeClause, $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded, 'HEX');
    } else {
        // field size should be at least 4 and max $GLOBALS['cfg']['LimitChars']
        $fieldsize = min(max($column['len'], 4), $GLOBALS['cfg']['LimitChars']);
        $html_output .= "\n" . $backup_field . "\n" . PMA_getHTMLinput($column, $column_name_appendix, $special_chars, $fieldsize, $onChangeClause, $tabindex, $tabindex_for_value, $idindex, 'HEX');
    }
    $html_output .= sprintf($fields_type_html, $fields_type_val);
    if ($is_upload && $column['is_blob']) {
        $html_output .= '<br />' . '<input type="file"' . ' name="fields_upload' . $vkey . '[' . $column['Field_md5'] . ']"' . ' class="textfield" id="field_' . $idindex . '_3" size="10"' . ' ' . $onChangeClause . '/>&nbsp;';
        list($html_out, ) = PMA_getMaxUploadSize($column, $biggest_max_file_size);
        $html_output .= $html_out;
    }
    if (!empty($GLOBALS['cfg']['UploadDir'])) {
        $html_output .= PMA_getSelectOptionForUpload($vkey, $column);
    }
    return $html_output;
}
/**
 * Get HTML for binary and blob column
 *
 * @param array   $column                description of column in given table
 * @param array   $data                  data to edit
 * @param array   $special_chars         special characters
 * @param integer $biggest_max_file_size biggest max file size for uploading
 * @param string  $backup_field          hidden input field
 * @param string  $column_name_appendix  the name atttibute
 * @param string  $unnullify_trigger     validation string
 * @param integer $tabindex              tab index
 * @param integer $tabindex_for_value    offset for the values tabindex
 * @param integer $idindex               id index
 * @param string  $text_dir              text direction
 * @param string  $special_chars_encoded replaced char if the string starts
 *                                       with a \r\n pair (0x0d0a) add an extra \n
 * @param string  $vkey                  [multi_edit]['row_id']
 * @param boolean $is_upload             is upload or not
 *
 * @return string                           an html snippet
 */
function PMA_getBinaryAndBlobColumn($column, $data, $special_chars, $biggest_max_file_size, $backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded, $vkey, $is_upload)
{
    $html_output = '';
    if ($GLOBALS['cfg']['ProtectBinary'] && $column['is_blob'] || $GLOBALS['cfg']['ProtectBinary'] == 'all' && $column['is_binary'] || $GLOBALS['cfg']['ProtectBinary'] == 'noblob' && !$column['is_blob']) {
        $html_output .= __('Binary - do not edit');
        if (isset($data)) {
            $data_size = PMA_CommonFunctions::getInstance()->formatByteDown(strlen(stripslashes($data)), 3, 1);
            $html_output .= ' (' . $data_size[0] . ' ' . $data_size[1] . ')';
            unset($data_size);
        }
        $html_output .= '<input type="hidden" name="fields_type' . $column_name_appendix . '" value="protected" />' . '<input type="hidden" name="fields' . $column_name_appendix . '" value="" />';
    } elseif ($column['is_blob']) {
        $html_output .= "\n" . PMA_getTextarea($column, $backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded);
    } else {
        // field size should be at least 4 and max $GLOBALS['cfg']['LimitChars']
        $fieldsize = min(max($column['len'], 4), $GLOBALS['cfg']['LimitChars']);
        $html_output .= "\n" . $backup_field . "\n" . PMA_getHTMLinput($column, $column_name_appendix, $special_chars, $fieldsize, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex);
    }
    if ($is_upload && $column['is_blob']) {
        $html_output .= '<br />' . '<input type="file"' . ' name="fields_upload' . $vkey . '[' . $column['Field_md5'] . ']"' . ' class="textfield" id="field_' . $idindex . '_3" size="10"' . ' ' . $unnullify_trigger . '/>&nbsp;';
        list($html_out, $biggest_max_file_size) = PMA_getMaxUploadSize($column, $biggest_max_file_size);
        $html_output .= $html_out;
    }
    if (!empty($GLOBALS['cfg']['UploadDir'])) {
        $html_output .= PMA_getSelectOptionForUpload($vkey, $column);
    }
    return $html_output;
}