<?
$formname      = "form_collection_cardform";
$translation   = \DynCom\mysyde\common\classes\Registry::get("translation");
$inputname     = "input_id";
$input_page_id = (isset($_REQUEST["input_page_id"]) ? $_REQUEST["input_page_id"] : "");
global $collection_setup_images;

?>

    <script type="text/javascript">

        var PATH_SETUP_ICON_COLLECTION = '<?php echo PATH_SETUP_ICON_COLLECTION; ?>';

        function change_setup_icon( _image ) {
            $('.setup_icon', $('#<?php echo $formname; ?>')).val(_image);
            $('.setup_icon_container img').remove();
            $('.setup_icon_container').append($('<img>').attr("src", PATH_SETUP_ICON_COLLECTION + _image));
        }
        $(document).ready(function(){
            if($('#is_multidomain').prop("checked") == true){
                $('#websiteSelection').show();
            }

            $('#is_multidomain').click(function(){
                if($(this).prop("checked") == true){
                    $('#websiteSelection').show();
                }
                else if($(this).prop("checked") == false){
                    $('#websiteSelection').hide();
                }
            });
        });

    </script>

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

    <ul class="toolbar_menu">
        <?php
        // Zurueck zur uebersicht
        if (is_page_edit()) {
            button("left", $translation->get("show_all"), $formname, "loadCard('list_collection_page', true)");
        }

        // Speichern button
        button("save", $translation->get("save"), $formname, "loadCard('save_collection_setup', true)");

        // Speichern und schliessen
        button("save", $translation->get("save_and_close"), $formname, "loadCard('save_collection_setup', true, '', true)");

        if ($input_collection["id"] != "") {
            button("copy", $translation->get("copy_collection_setup"), $formname, "loadCard('copy_collection_setup', true)");
        }

        ?>
        <li>
            <ul>
                <?php
                // Loeschen  button
                if ($input_collection["id"] != "" && is_page_edit() === FALSE) {
                    echo button("delete", $translation->get("delete-collection"), $formname, "loadCard('delete_collection_setup', true, '{$translation->get('delete_collection_setup_confirm')}', true)", "", FALSE);
                }

                // Zuruecksetzen
                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_id" type="hidden" value="<?= $input_collection["id"] ?>">
        <input type="hidden" name="get_real_page_link_id" value="1" />
        <input type="hidden" name="input_page_id" value="<?php echo $input_page_id; ?>" />
        <input name="data-sitepartid" type="hidden" value="8">
        <input class="setup_icon" name="setup_icon" id="setup_icon" type="hidden"
               value="<?php echo $input_collection['icon']; ?>" />

        <table class="cardform" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td>

                    <? input($translation->get("textkey"), "input_code", "code", $input_collection["code"], 20) ?>
                    <? input($translation->get("collection_name"), "input_description", "text", $input_collection["description"], 255) ?>
                    <?php
                        $types = [
                            '1' => $translation->get("normal"),
                            '2' => $translation->get("job"),
                            '3' => $translation->get("calendar"),
                            '4' => $translation->get("top_knowledgecenter"),
                        ];
                        $preselect = 1;
                        if(isset($input_collection['collection_type']) ){
                            $preselect = $input_collection['collection_type'];
                        }
                    ?>
                    <?php input_select($translation->get("collection_type"), "collection_type", $values = array_keys($types), $value_names = array_values($types), $preselect, FALSE, FALSE); ?>
                    <?php collection_setup_world($input_collection); ?>
                </td>
                <td>
                    <?php
                    echo "<h3>".$translation->get("normal_collection_settings")."</h3>";
                    input($translation->get("collection_linked"), "input_linked", "checkbox", $input_collection["linked"]);
                    input($translation->get("desc_title"),"input_desc_title", "checkbox",$input_collection["desc_title"]);
                    input($translation->get("show_in_menu"),"input_show_in_menu", "checkbox",$input_collection["show_in_menu"]);
                    input($translation->get("Filter"),"input_show_filter", "checkbox",$input_collection["show_filter"]);
                    echo "<h3 class='irgendwas'>".$translation->get("advanced_collection_settings")."</h3>";
                    input($translation->get("custom"),"is_custom_collection", "checkbox",$input_collection["is_custom_collection"]); 
                    input($translation->get("show_group_name"),"input_show_group_name", "checkbox",$input_collection["show_group_name"]);
                    input($translation->get("show_in_all_languages"), "input_all_languages", "checkbox", $input_collection["all_languages"]);
                    input($translation->get("frontend_creation"), "frontend_creation", "checkbox", $input_collection['is_multidomain'], NULL, FALSE, FALSE, '');
                    input($translation->get("is_multidomain").'?', "is_multidomain", "checkbox", $input_collection['is_multidomain'], NULL, FALSE, FALSE, '');
                    if ($input_collection["id"] != "") {
                        try {
                        collection_setup_websites($input_collection);
                        }catch(Exception $e) {
                            echo 'Message: ' .$e->getMessage();
                          }
                    }   
                    ?>
                </td>
            </tr>
        </table>
    </form>

<?
if ($input_collection['id'] != "") {
    if(!$input_collection['is_custom_collection']){
        require_once("edit_collection_setup_line_listform.inc.php");
    }
    
    require_once("edit_collection_setup_group_listform.inc.php");
}
?>