<?php
$odd_row = true;
$type = $collation = $func = $value = array();
/**
 * Get already set search criteria (if any)
 */

// Displays column rows for search criteria input
for ($i = 0; $i < 4; $i++): ?>
    <?php
    // After X-Axis and Y-Axis column rows, display additional criteria
    // option
    if ($i == 2): ?>
        <tr>
            <td>
                <?= __("Additional search criteria"); ?>
            </td>
        </tr>
    <?php endif; ?>
    <tr class="noclick <?= ($odd_row ? 'odd' : 'even'); ?>">
        <?php $odd_row = ! $odd_row; ?>
        <!-- Select options for column names -->
        <th>
            <select name="criteriaColumnNames[]" id="tableid_<?= $i; ?>" >
                <option value="pma_null">
                    <?= __('None'); ?>
                </option>
                <?php for ($j = 0, $nb = count($columnNames); $j < $nb; $j++): ?>
                    <?php if (isset($_POST['criteriaColumnNames'][$i])
                        && $_POST['criteriaColumnNames'][$i] == htmlspecialchars($columnNames[$j])
                    ): ?>
                        <option value="<?= htmlspecialchars($columnNames[$j]); ?>" selected="selected">
                            <?= htmlspecialchars($columnNames[$j]); ?>
                        </option>
                    <?php else: ?>
                        <option value="<?= htmlspecialchars($columnNames[$j]); ?>">
                            <?= htmlspecialchars($columnNames[$j]); ?>
                        </option>
                    <?php endif; ?>
                <?php endfor; ?>
            </select>
        </th>
        <?php
        if (isset($_POST['criteriaColumnNames'])
            && $_POST['criteriaColumnNames'][$i] != 'pma_null'
        ) {
            $key = array_search(
                $_POST['criteriaColumnNames'][$i],
                $columnNames
            );
            $properties = $self->getColumnProperties($i, $key);
            $type[$i] = $properties['type'];
            $collation[$i] = $properties['collation'];
            $func[$i] = $properties['func'];
            $value[$i] = $properties['value'];
        } ?>
        <!-- Column type -->
        <td dir="ltr">
            <?= (isset($type[$i]) ? htmlspecialchars($type[$i]) : ''); ?>
        </td>
        <!-- Column Collation -->
        <td>
            <?= (isset($collation[$i]) ? $collation[$i] : ''); ?>
        </td>
        <!-- Select options for column operators -->
        <td>
            <?= (isset($func[$i]) ? $func[$i] : ''); ?>
        </td>
        <!-- Inputbox for search criteria value -->
        <td>
            <?= (isset($value[$i]) ? $value[$i] : ''); ?>
        </td>
    </tr>
    <!-- Displays hidden fields -->
    <tr>
        <td>
            <input type="hidden"
                   name="criteriaColumnTypes[<?= $i; ?>]"
                   id="types_<?= $i; ?>"
                <?php if (isset($_POST['criteriaColumnTypes'][$i])): ?>
                    value="<?= htmlspecialchars($_POST['criteriaColumnTypes'][$i]); ?>"
                <?php endif; ?> />
            <input type="hidden"
                   name="criteriaColumnCollations[<?= $i; ?>]"
                   id="collations_<?= $i; ?>" />
        </td>
    </tr>
<?php endfor; ?>
