function create_selection($selection, $flag, $access_rights)
{
    $right = "<tr><td align='right'><label for='" . clean_id_string($selection) . "'>" . get_lang($selection) . ":</label></td>\n\t\t\t  <td align='left'><input id='" . clean_id_string($selection) . "' type='checkbox' name='" . $selection . "' value='1' checked='checked' /></td></tr>\n\t\t\t  <tr><td colspan='2' class='info'>" . get_lang($selection . '_info') . "</td></tr>";
    if (preg_match("/{$flag}/", $access_rights)) {
        return $right;
    }
}
function renderCustomFields($field, $home_id)
{
    global $db;
    $attributesString = "";
    foreach ($field->attribute as $attribute) {
        $attributesString .= $attribute['key'] . "='{$attribute}' ";
    }
    //get used custom value or get default
    $custom_fields = json_decode($db->getCustomFields($home_id), True);
    if (array_key_exists((string) $field['key'], $custom_fields)) {
        $fieldValue = (string) $custom_fields[(string) $field['key']];
    } else {
        $fieldValue = (string) $field->default_value;
    }
    $idString = "id='" . clean_id_string($field['key']) . "'";
    $nameString = "name='fields[" . $field['key'] . "]'";
    $fieldType = $field['type'];
    if ($fieldType == "select") {
        $inputElementString = "<select {$idString} {$nameString}>";
        foreach ($field->option as $option) {
            $optionValue = (string) $option['value'];
            $selectedString = $optionValue == $fieldValue ? "selected='selected'" : "";
            $valueString = "value='{$optionValue}'";
            $inputElementString .= "<option {$selectedString} {$valueString}>{$option}</option>";
        }
        $inputElementString .= "</select>";
    } else {
        if ($fieldType == "checkbox_key_value") {
            if ($fieldValue) {
                // convert the XML object to string
                $attributesString .= "checked='checked' ";
            }
            $fieldValue = $field['key'];
            $fieldType = "checkbox";
        } else {
            if ($fieldType == "checkbox") {
                if ($fieldValue) {
                    // convert the XML object to string
                    $attributesString .= "checked='checked' ";
                }
            }
        }
        $inputElementString = "<input {$idString} {$nameString} " . "type='{$fieldType}' value='{$fieldValue}' {$attributesString}/>";
    }
    echo "<tr><td class='right'><label for='" . clean_id_string($field['key']) . "'>" . $field['key'] . ":</label></td><td class='left'>{$inputElementString}<label for='" . clean_id_string($field['key']) . "'>";
    if (!empty($field->caption)) {
        echo $field->caption;
    }
    if (!empty($field->desc)) {
        echo "<br/><span class='info'>(" . $field->desc . ")</span>";
    }
    echo "</label></td></tr>\n";
}
function renderParam($param, $param_access_enabled, $home_id)
{
    global $db;
    $attributesString = "";
    foreach ($param->attribute as $attribute) {
        $attributesString .= $attribute['key'] . "='{$attribute}' ";
    }
    $disabledString = $param_access_enabled ? "" : "disabled ";
    //get last used param or get default
    $last_param = json_decode($db->getLastParam($home_id), True);
    if (array_key_exists((string) $param['key'], $last_param)) {
        $paramValue = (string) $last_param[(string) $param['key']];
    } else {
        $paramValue = (string) $param->default;
    }
    $idString = "id='" . clean_id_string($param['key']) . "'";
    $nameString = "name='params[" . $param['key'] . "]'";
    $paramType = $param['type'];
    if ($paramType == "select") {
        $inputElementString = "<select {$idString} {$nameString}>";
        foreach ($param->option as $option) {
            $optionValue = (string) $option['value'];
            $selectedString = $optionValue == $paramValue ? "selected='selected'" : "";
            $valueString = "value='{$optionValue}'";
            $inputElementString .= "<option {$selectedString} {$valueString}>{$option}</option>";
        }
        $inputElementString .= "</select>";
    } else {
        if ($paramType == "checkbox_key_value") {
            if ($paramValue) {
                // convert the XML object to string
                $attributesString .= "checked='checked' ";
            }
            $paramValue = $param['key'];
            $paramType = "checkbox";
        } else {
            if ($paramType == "checkbox") {
                if ($paramValue) {
                    // convert the XML object to string
                    $attributesString .= "checked='checked' ";
                }
            }
        }
        $inputElementString = "<input {$idString} {$nameString} " . "type='{$paramType}' value='{$paramValue}' " . "{$disabledString} {$attributesString}/>";
    }
    echo "<tr><td class='right'><label for='" . clean_id_string($param['key']) . "'>" . $param['key'] . ":</label></td><td class='left'>{$inputElementString}<label for='" . clean_id_string($param['key']) . "'>";
    if (!empty($param->caption)) {
        echo $param->caption;
    }
    if (!empty($param->desc)) {
        echo "<br/><span class='info'>(" . $param->desc . ")</span>";
    }
    echo "</label></td></tr>\n";
}
function create_selection($selection, $flag)
{
    return "<tr><td align='right'><label for='" . clean_id_string($selection) . "'>" . get_lang($selection) . ":</label></td>\n\t\t<td align='left'><input id='" . clean_id_string($selection) . "' type='checkbox' name='" . $selection . "' value='1' checked='checked' /></td></tr><tr>\n\t\t<td align='left' class='info' colspan='2'>" . get_lang($selection . '_info') . "</td></tr>";
}