<?php
$translation    = \DynCom\mysyde\common\classes\Registry::get("translation");
$formname       = "form_page_card";
$main_layout_id = $GLOBALS["language"]["main_layout_id"];
$main_page_id   = (int)$input_page["id"];
$from           = isset($_REQUEST['from']) ? $_REQUEST['from'] : '';

function create_checkboxes( $main_layout_id, $main_page_id, $type ) {
    $query             = "
			SELECT id, path, default_active
			FROM main_layout_inclusions
			WHERE main_layout_id = '" . $main_layout_id . "' AND type = '" . $type . "'
			ORDER BY sorting ASC";
    $result            = @mysqli_query($GLOBALS['mysql_con'], $query);
    $layout_inclusions = array();
    IF (@mysqli_num_rows($result) > 0) {
        WHILE ($layout_inclusions = @mysqli_fetch_assoc($result)) {
            $query2        = "SELECT active FROM main_page_layout_inclusion_link WHERE
					main_layout_includes_id = '" . $layout_inclusions["id"] . "' AND
					main_page_id = " . $main_page_id;
            $result2       = mysqli_query($GLOBALS['mysql_con'], $query2);
            $boxname_array = array();
            $boxname_array = explode("/", $layout_inclusions["path"]);
            $array_index   = count($boxname_array) - 1;
            $boxname       = $boxname_array[$array_index];
            IF (@mysqli_num_rows($result2) == 0) {
                input($boxname, "input_script_" . $layout_inclusions["id"] . "_active", "checkbox", $layout_inclusions["default_active"]);
            } ELSE {
                input($boxname, "input_script_" . $layout_inclusions["id"] . "_active", "checkbox", @mysqli_result($result2, 0));
            }
        }
    }
}

function create_component_checkbox( $main_page_id ) {
    $query             = "SELECT id, title, default_active FROM main_component WHERE (main_language_id = " . (int)$GLOBALS["language"]['id'] . " OR all_languages = 1)";
    $result            = @mysqli_query($GLOBALS['mysql_con'], $query);
    $layout_inclusions = array();
    IF (@mysqli_num_rows($result) > 0) {
        WHILE ($layout_inclusions = @mysqli_fetch_assoc($result)) {
            $query2  = "SELECT active FROM main_page_component_include_link WHERE
					main_component_id = '" . $layout_inclusions["id"] . "' AND
					main_page_id = '" . $main_page_id."'";
            $result2 = mysqli_query($GLOBALS['mysql_con'], $query2);
            $boxname = $layout_inclusions['title'];
            IF (@mysqli_num_rows($result2) == 0) {
                input($boxname, "input_component_" . $layout_inclusions["id"] . "_active", "checkbox", $layout_inclusions["default_active"]);
            } ELSE {
                input($boxname, "input_component_" . $layout_inclusions["id"] . "_active", "checkbox", @mysqli_result($result2, 0));
            }
        }
    }
}

?>



<div id="overlaycrumb">
    <?php if ($input_page["id"] == "") {
        echo $translation->get("new_site");
    } else {
        echo $translation->get("edit_site");
    }
    ?>
</div>

<ul class="toolbar_menu">

    <?
    if ($from == "page_line_listform") {
        button("left", $translation->get("back"), $formname, "loadCard('edit_content_page', true)");
    }
    ?>
    <?= button("save", $translation->get("save"), $formname, "loadCard('save_page', true)"); ?>
    <?= button("save", $translation->get("save_and_close"), $formname, "loadCard('save_page', true, '', true)"); ?>
    <div style="display:none;">
    <?
        if ($input_page["id"] != "") {
            echo button("copy", $translation->get("copy_site"), $formname, "loadCard('copy_page', true)");
        }
    ?>
    </div>
    <li>
        <ul>
            <?php
            if ($input_page["id"] != "") {
                echo button("delete", $translation->get("delete"), $formname, "loadCard('delete_page', true, '{$translation->get('delete_textcontent_confirm')}', true)", "", FALSE);
            }
            ?>
            <?= button("reset", $translation->get("restore"), $formname, "?action=edit", "", FALSE); ?>
        </ul>
    </li>


</ul>
<div class="clearfix"></div>

<?php
if ($messages !== null) {
    if (count($messages)) {
            echo '<div id="overlayMessages">' . join("\r\n", $messages) . '</div>';
    } 
  }
?>

<form id="<?= $formname ?>" name="<?= $formname ?>" method="post">
    <input name="input_page_id" type="hidden" value="<?= $input_page["id"] ?>">
    <input name="input_main_layout_id" type="hidden" value="<?= $main_layout_id ?>">

    <table class="cardform" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td>
                <? input($translation->get("description"), "input_page_name", "text", $input_page["title"], 255) ?>
                <? input($translation->get("browsertitle"), "input_browser_title", "text", $input_page["subtitle"], 255) ?>
                <? input($translation->get("meta_description"), "input_meta_description", "textarea", $input_page["meta_description"]) ?>
                <? input($translation->get("meta_keywords"), "input_meta_keywords", "textarea", $input_page["meta_keywords"]) ?>
            </td>
            <td>
                <? input($translation->get("active"), "input_active", "checkbox", $input_page["active"]) ?>
                <? input($translation->get("no_index"), "input_no_index", "checkbox", $input_page["no_index"]) ?>
                <? input($translation->get("validity_from"), "input_validity_from", "date", datefromsql($input_page["validity_from"]), 10) ?>
                <? input($translation->get("validity_to"), "input_validity_to", "date", datefromsql($input_page["validity_to"]), 10) ?>
            </td>
        </tr>
        <tr>
            <td>
                <h2><?php echo $translation->get("Bausteine"); ?></h2>
                <? create_component_checkbox($main_page_id); ?>
            </td>

            <td>
                <h2><?php echo $translation->get("edit_css_javascript_config"); ?></h2>
                <? create_checkboxes($main_layout_id, $main_page_id, 'js'); ?>
                <? create_checkboxes($main_layout_id, $main_page_id, 'css'); ?>
            </td>
        </tr>
    </table>
</form>