<?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 add_datacenter_theme(){

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


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

    $GLOBALS['breadcrumbs'] = array( 'dashboard', 'lm_list_datacenters', 'lms_add_datacenter');

    echo page_header(__('Add Datacenters'), 'fas fa-server', '', 1, 0, '');

    error_handle($error);

    if(!empty($done)){
        show_alert(__('The Datacenter has been saved. Return to <a href="index.php?act=list_datacenters">List Datacenter</a> </br></br> You can add floors <a href="index.php?act=add_dcfloors">Add Datacenter Floors</a>'), "0", "list_datacenters");
    }

    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;
            }

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

        });

    </script>
        <div class="card p-2 mx-3">
            <div id="add_location_content">
                <form accept-charset="'.$globals['charset'].'" name="add_datacenter" method="post" action="" class="form-horizontal" id="add_datacenter">
                    <input type="hidden" name="add_datacenter" id="add_datacenter" value=1/>
                    <div class="row mx-auto w-100 mb-3">
                        <div class="col-sm-12 col-md-6 my-2">
                            <label class="control-label">'.__('Datacenter Country').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Location Name of Data Center').'"><i class="fas text-primary fa-info-circle"></i></a></label>
                            <select class="custom-select form-select w-100" name="server_country_code" id="server_country_code" >
                                <option value="">'.__('Select your country code').'</option>';
                                foreach($countries as $k => $v){
                                    echo '<option data-image="'.location_flag($k).'" value="'.$k.'" '.ex_POSTselect('server_country_code', $k).'>'.$v.'</option>';
                                }						
                                echo '
                            </select>
                        </div>
                        <div class="col-sm-12 col-md-6 my-2">
                            <label class="control-label">'.__('Data Center Name').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Data Center Country').'"><i class="fas text-primary fa-info-circle"></i></a></label>
                            <input type="text" class="form-control w-100" name="dc_name" id="dc_name" size="15" value="'.POSTval('dc_name', $dc_locations['dc_name']).'" required/>
                        </div>
                        <div class="col-sm-12 col-md-6 my-2">
                            <label class="control-label">'.__('Location Name').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Data Center Country').'"><i class="fas text-primary fa-info-circle"></i></a></label>
                            <input type="text" class="form-control w-100" name="dc_location" id="dc_location" size="15" value="'.POSTval('dc_location', $dc_locations['dc_location']).'" required/>
                        </div>
                        <div class="col-sm-12 col-md-6 my-2">
                            <label class="control-label">'.__('Location Address').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Location Name of Data Center').'"><i class="fas text-primary fa-info-circle"></i></a></label>
                            <input type="text" class="form-control w-100" name="dc_address" id="dc_address" size="15" value="'.POSTval('dc_address', $dc_locations['dc_address']).'" required/>
                        </div>
                        <div class="col-sm-12 col-md-6 my-2">
                            <label class="control-label">'.__('Remote Agent').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Remote Agent Details').'"><i class="fas text-primary fa-info-circle"></i></a></label>
                            <input type="text" class="form-control w-100" name="dc_remote_agent" id="dc_remote_agent" size="15" value="'.POSTval('dc_remote_agent', $dc_locations['dc_remote_agent']).'" required/>
                        </div>
                        <div class="col-sm-12 col-md-6 my-2">
                            <label class="control-label">'.__('Location Email').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Data centers Email id').'"><i class="fas text-primary fa-info-circle"></i></a></label>
                            <input type="text" class="form-control w-100" name="dc_email" id="dc_email" size="15" value="'.POSTval('dc_email', $dc_locations['dc_email']).'" required/>
                        </div>
                        <div class="col-sm-12 col-md-6 my-2">
                            <label class="control-label">'.__('Location Phone').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Data centers Phone Number. You can add code also like (+91) we allow only (+) and (-) sign for phone number').'"><i class="fas text-primary fa-info-circle"></i></a></label>
                            <input type="text" class="form-control w-100" name="dc_phone" id="dc_phone" size="15" value="'.POSTval('dc_phone', $dc_locations['dc_phone']).'" required/>
                        </div>
                        <div class="col-sm-12 col-md-6 my-2">
                            <label class="control-label">'.__('Location Description').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Data Centers details').'"><i class="fas text-primary fa-info-circle"></i></a></label>
                            <div id="description" class="bgaddv p-0">
                                <textarea  name="dc_description" id="dc_description" rows="10" class="form-control">'.POSTval('dc_description', $dc_locations['dc_description']).'</textarea>
                            </div>
                        </div>
                    </div>
                    <div class="text-center">
                        <button type="submit" onclick="" name="save_user_plan_btn" class="go_btn mt-5 mb-3" value="'.__('Save Location').'">'.__('Save Location').'</button>
                    </div>
                </form>
            </div>
        </div>
    ';
softfooter();

}
