<?php

//////////////////////////////////////////////////////////////
//===========================================================
// add_datacenter_theme.php
//===========================================================
// SOFTACULOUS VIRTUALIZOR
// Version : 1.0
// Inspired by the DESIRE to be the BEST OF ALL
// ----------------------------------------------------------
// Started by: Alons
// Date:       8th Mar 2010
// Time:       23:00 hrs
// Site:       https://www.virtualizor.com/ (SOFTACULOUS VIRTUALIZOR)
// ----------------------------------------------------------
// Please Read the Terms of use at https://www.virtualizor.com
// ----------------------------------------------------------
//===========================================================
// (c)Softaculous Ltd.
//===========================================================
//////////////////////////////////////////////////////////////

if(!defined('VIRTUALIZOR')){

	die('Hacking Attempt');

}

function edit_dcfloors_theme(){

    global $theme, $globals, $kernel, $l, $error, $done, $SESS, $baremetals, $dc_locations, $countries, $floor_plans, $list_datacenters, $floor_details;

    softheader($l['<title>']);

    $GLOBALS['breadcrumbs'] = array( 'dashboard', 'lm_list_dcfloors','lms_edit_dcfloor');

    echo page_header(__('Edit Datacenter Floor'), 'fas fa-server', '', 1, 0, '');

    error_handle($error);

    if(!empty($done)){
        show_alert(__('The Datacenter Floor has been updated. Return to <a href="index.php?act=list_dcfloors">List Datacenter Floors </a>'), "0", "list_dcfloors");
    }

    echo'
    <script>

    $(document).ready(function(){

        function formatOption(state) {
            if (!state.id) {
                return state.text; // default option (placeholder)
            }

            let img = $(state.element).data("image");

            if (!img) {
                return state.text;
            }

            let $state = $(`
                <span style="display:flex; align-items:center;">
                    <img src="${img}" style="width:22px; height:15px; margin-right:8px; object-fit:cover;">
                    ${state.text}
                </span>
            `);

            return $state;
        }

        $("#selected_dc").select2({
            templateResult: formatOption,
            templateSelection: formatOption,
        });

    });

    </script>
        <div class="card p-2 mx-3">
            <!-- Add Floor Form -->
            <form accept-charset="'.$globals['charset'].'" name="edit_floor_plan" method="post" action="" class="form-horizontal" id="edit_floor_plan">
                <input type="hidden" value="1" class="" name="edit_floor_plan">
                <input type="hidden" value="'.$floor_details['flid'].'" class="" name="flid">
                <div class="floor-section">
                    <div class="row m-0 w-100 mb-3">
                        <div class="col-sm-12 col-md-6 my-2">
                            <label class="control-label">'.__('Datacenter Name').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('A unique name for your reference').'"><i class="fas text-primary fa-info-circle"></i></a></label>
                            <select class="custom-select form-select w-100" name="selected_dc" id="selected_dc" required>
                                <option value="0" '.(POSTval('selected_dc') == 0 ?  'selected="selected"' : '').'>'.__('Select Datacenter').'</option>';
                                foreach($list_datacenters as $dcid => $dcdeatils){
                                    echo '<option data-image="'.location_flag($dcdeatils['country']).'" value="'.$dcid.'" '.ex_POSTselect('selected_dc', $dcid, $floor_details['dcid']).'>'.$dcdeatils['name'].' ('.$countries[$dcdeatils['country']].')</option>';
                                }
                            echo'
                            </select>
                        </div>
                        <div class="col-sm-0 col-md-6 my-2"></div>
                        <div class="col-sm-12 col-md-6 my-2">
                            <label class="control-label">'.__('Floor Name').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('A unique name for your reference').'"><i class="fas text-primary fa-info-circle"></i></a></label>
                            <input type="text" class="form-control w-100" id="floor_name" name="floor_name" size="15" value="'.POSTval('floor_name', $floor_details['floor_name']).'" />
                        </div>
                        <div class="col-sm-12 col-md-6 my-2">
                            <label class="control-label">'.__('Floor Number').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('A unique name for your reference').'"><i class="fas text-primary fa-info-circle"></i></a></label>
                            <input type="number" class="form-control w-100" id="floor_number" name="floor_number" size="15" value="'.POSTval('floor_number', $floor_details['floor_number']).'" />
                        </div>
                        <div class="col-sm-12 col-md-6 my-2">
                            <label class="control-label">'.__('Floor Rows').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('A unique name for your reference').'"><i class="fas text-primary fa-info-circle"></i></a></label>
                            <input type="number" class="form-control w-100" placeholder="e.g. 5" id="floor_rows" name="floor_rows" size="15" value="'.POSTval('floor_rows', $floor_details['floor_rows']).'" />
                        </div>
                        <div class="col-sm-12 col-md-6 my-2">
                            <label class="control-label">'.__('Floor Columns').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('A unique name for your reference').'"><i class="fas text-primary fa-info-circle"></i></a></label>
                            <input type="number" class="form-control w-100" placeholder="e.g. 10" id="floor_cols" name="floor_cols" size="15" value="'.POSTval('floor_cols', $floor_details['floor_cols']).'" />
                        </div>
                    </div>
                    <!--
                    <div class="w-1/2 m-0 row w-100 mb-3">
                        <div id="floorPreview" class="mx-3 p-3 border text-center rounded w-100">
                            <em>No floor selected yet</em>
                        </div>
                    </div>
                    -->
                </div>
                <div class="form-group text-center mt-4">
                    <button type="submit" onclick="" class="go_btn mt-5 mb-3" value="'.__('Save floors').'">
                        </i>'.__('Save Floor Plan').'
                    </button>
                </div>
            </form>
        </div>
    ';
softfooter();

}
