<input id="cb-select-all-2" type="checkbox"> </td> <th class="manage-column column-col_value_name" scope="col"><?php echo __('Value', 'idp-plugin'); ?> </th> <th class="manage-column column-col_value_attribute" scope="col"><?php echo __('Attribute', 'idp-plugin'); ?> </th> </tr> </tfoot> <tbody class="searchable"> <?php $values = Idp_Main::getSelectableValues($attribute_id); $categories = Idp_Main::getAttributeCategories(); $row_alternate = true; foreach ($values as $value) { if ($row_alternate) { ?> <tr class=\"alternate\" valign=\"top\"> <?php } else { ?> <tr valign=\"top\"> <?php } ?> <th class="check-column" scope="row"> <label class="screen-reader-text" for="cb-select-<?php
function idp_buildInputField($attributeID, $attribute, $type, $required, $building_id = NULL) { global $wpdb; $preset_values = []; //will carry the preset values, if we edit a building if (!is_null($building_id)) { $result = $wpdb->get_results("\r\n\t\t\tSELECT value \r\n\t\t\tFROM {$wpdb->prefix}building_attribute\r\n\t\t\tWHERE attribute = " . $attributeID . " AND building = " . $building_id, ARRAY_A); if (isset($result[0])) { foreach ($result as $array) { foreach ($array as $value) { $preset_values[] = $value; } } } } if ($required == 1) { $required_attribute = "required=\"required\""; $required_class = "required"; } else { $required_attribute = ""; $required_class = ""; } $attribute = str_replace(' ', '', $attribute); $tmp_val = ""; switch ($type) { case "textfield": if (isset($preset_values[0])) { $tmp_val = $preset_values[0]; } echo "<input type=\"text\" class=\"form-control " . $required_class . "\" id=\"" . $attribute . "\" name=\"" . $attributeID . "\" value=\"" . $tmp_val . "\" " . $required_attribute . ">\n"; break; case "textarea": if (isset($preset_values[0])) { $tmp_val = $preset_values[0]; } echo "<textarea class=\"form-control " . $required_class . "\" rows=\"5\" id=\"" . $attribute . "\" name=\"" . $attributeID . "\" " . $required_attribute . ">" . $tmp_val . "</textarea>"; break; case "checkbox": if (isset($preset_values[0])) { $tmp_val = $preset_values[0]; } $selected_string = ""; $selected_state = false; $options[1] = 'Ja'; $options[0] = 'Nein'; $optionsString = ""; echo "<select class=\"form-control " . $required_class . "\" id=\"" . $attribute . "\" name=\"" . $attributeID . "\" " . $required_attribute . ">"; foreach ($options as $opt => $label) { if (strval($opt) === strval($tmp_val)) { $selected_string = "selected=\"selected\""; $selected_state = true; } $optionsString .= "<option value=\"" . $opt . "\"" . $selected_string . ">" . $label . "</option>"; $selected_string = ""; } if (!$selected_state) { echo "<option value=\"\" selected=\"selected\" disabled=\"disabled\">------</option> "; } echo $optionsString; echo "</select>"; break; case "dropdown": $options = Idp_Main::getSelectableValues($attributeID); if (isset($preset_values[0])) { $tmp_val = $preset_values[0]; } $selected_string = ""; $selected_state = false; $optionsString = ""; echo "<select class=\"form-control " . $required_class . "\" id=\"" . $attribute . "\" name=\"" . $attributeID . "\" " . $required_attribute . ">"; foreach ($options as $opt) { if ($opt->value === $tmp_val) { $selected_string = "selected=\"selected\""; $selected_state = true; } $optionsString .= "<option value=\"" . $opt->value . "\"" . $selected_string . ">" . $opt->value . "</option>"; $selected_string = ""; } if (!$selected_state) { echo "<option value=\"\" selected=\"selected\" disabled=\"disabled\">------</option> "; } echo $optionsString; echo "</select>"; break; case "multiselect": $options = Idp_Main::getSelectableValues($attributeID); if (isset($preset_values[0])) { $tmp_val = $preset_values; } $selected_string = ""; $selected_state = false; echo "<select multiple class=\"form-control " . $required_class . "\" id=\"" . $attribute . "\" name=\"" . $attributeID . "[]\"" . $required_attribute . ">"; foreach ($options as $opt) { if (!empty($tmp_val) && in_array($opt->value, $tmp_val)) { $selected_string = "selected=\"selected\""; $selected_state = true; } echo "<option value=\"" . $opt->value . "\"" . $selected_string . ">" . $opt->value . "</option>"; $selected_string = ""; } echo "</select>"; break; } }