<?php // Admin template 

if($_SERVER['REQUEST_METHOD'] == "POST" && $_POST['save-it'] == 'true') {
    if(!array_key_exists('item_border', $_POST['options'])) {
        $_POST['options']['item_border'] = null;
    }
    if(!array_key_exists('item_modal', $_POST['options'])) {
        $_POST['options']['item_modal'] = null;
    }
    foreach ( $_POST['options'] as $name => $value ) {
        if ( ! is_array($value) ) {
            $_POST['options'][$name] = sanitize_text_field($value);
        }
    }
// var_dump($_POST);
    $am = new AdminMgr();
    $args = $am->updateOptions($_POST['options']);
    echo '<div class="updated"><p><strong>Settings saved.</strong></p></div>';
}
// var_dump($args);

$defaults = array(
    'cart_vendors' => array(
        'Cart66' => CART_CART66,
        'WooCommerce' => CART_WOOCOM),
    'ui_themes'           => array(
        'None'                => 'none',
        'Base'                => 'base',
        'Black-tie'           => 'black-tie',
        'Blitzer'             => 'blitzer',
        'Cupertino'           => 'cupertino',
        'Dark hive'           => 'dark-hive',
        'Dot luv'             => 'dot-luv',
        'Eggplant'            => 'eggplant',
        'Excite bike'         => 'excite-bike',
        'Flick'               => 'flick',
        'Hot sneaks'          => 'hot-sneaks',
        'Humanity'            => 'humanity',
        'le Frog'             => 'le-frog',
        'Mint chocolate'      => 'mint-choc',
        'Overcast'            => 'overcast',
        'Pepper grinder'      => 'pepper-grinder',
        'Redmond'             => 'redmond',
        'Smoothness'          => 'smoothness',
        'South street'        => 'south-street',
        'Start'               => 'start',
        'Sunny'               => 'sunny',
        'Swanky Purse'        => 'swanky-purse',
        'Trontastic'          => 'trontastic',
        'ui-darkness'         => 'ui-darkness',
        'ui-lightness'        => 'ui-lightness',
        'Vader'               => 'vader')
    );

$carts = array_keys($defaults['cart_vendors']);
$ui_themes = $defaults['ui_themes'];


?>


<h2>Cartalog Options</h2>


<form name="opts_form" method="post" action="">
<input type="hidden" name="save-it" value="true">
    <div id="widgets-left" style="margin-right: 50px;">
        <div id="available-widgets">
        
            <div class="widgets-holder-wrap">
                <div class="sidebar-name">
                    <div class="sidebar-name-arrow"><br/></div>
                    <h3>General <span><img class="ajax-feedback" alt="" title="" src="images/wpspin_light.gif"/></span></h3>
                </div>
                <div class="widget-holder">
                    <div>
                        <ul>
                            <li class="hidden">
                                <label class="cartalog_label" for="options-cart_vendor">Cart Vendor *</label>
                                <select id="options-cart_vendor" name='options[cart_vendor]'>
<?php
    foreach($carts as $cart){
        if($cart === $args['cart_vendor']){
            $selected = "selected";
        }
        else {
            $selected = "";
        }
?>
                                    <option value="<?php echo $cart?>" <?php echo $selected?>><?php echo $cart?></option>
<?php } ?>
                                </select>
                            </li>
                            <li>
                                <label class="cartalog_label" for="options-custom_styles">Custom Stylesheet</label>
                                <input class="cartalog_input"
                                        type="text"
                                        style="width: 175px;"
                                        id="options-custom_styles"
                                        name="options[custom_styles]" value="<?php echo $args['custom_styles']?>" />
                            </li>
                        </ul>
                    </div>
                </div>
            </div>

            <div class="widgets-holder-wrap">
                <div class="sidebar-name">
                    <div class="sidebar-name-arrow"><br/></div>
                    <h3>Categories <span><img class="ajax-feedback" alt="" title="" src="images/wpspin_light.gif"/></span></h3>
                </div>
                <div class="widget-holder">
                <div>
                <ul>
<li>
<label class="cartalog_label" for="options-category_width">Category Width</label>
<input class="cartalog_input" type="text" style="width: 75px;" id="options-category_width" name="options[category_width]" value="<?php echo $args['category_width']?>" />
</li>

<li>
<label class="cartalog_label" for="options-category_background">Title Background Color</label>
<input class="cartalog_input" type="text" style="width: 75px;" id="options-category_background" name="options[category_background]" value="<?php echo $args['category_background']?>" />
</li>

<li>
<label class="cartalog_label" for="options-category_color">Title Text Color</label>
<input class="cartalog_input" type="text" style="width: 75px;" id="options-category_color" name="options[category_color]" value="<?php echo $args['category_color']?>" />
</li>




            </ul>
          </div>
        </div>
      </div>
            <div class="widgets-holder-wrap">
                <div class="sidebar-name">
                    <div class="sidebar-name-arrow"><br/></div>
                    <h3>Items <span><img class="ajax-feedback" alt="" title="" src="images/wpspin_light.gif"/></span></h3>
                </div>
                <div class="widget-holder">
                <div>
                <ul>
<li>
<label class="cartalog_label" for="options-item_width">Item Width *</label>
<input class="cartalog_input" type="text" style="width: 75px;" id="options-item_width" name="options[item_width]" value="<?php echo $args['item_width']?>" />
</li>

<li>
<label class="cartalog_label" for="options-item_background">Background Color</label>
<input class="cartalog_input" type="text" style="width: 75px;" id="options-item_background" name="options[item_background]" value="<?php echo $args['item_background']?>" />
</li>

<li>
<label class="cartalog_label" for="options-item_color">Text Color</label>
<input class="cartalog_input" type="text" style="width: 75px;" id="options-item_color" name="options[item_color]" value="<?php echo $args['item_color']?>" />
</li>

<li>
<label class="cartalog_label" for="options-item_border">Item Border</label>
<input class="cartalog_input" type="checkbox" <?php if ($args['item_border'] === '1') : echo 'checked="checked" '; endif; ?> id="options-item_border" name="options[item_border]" value="1" />
</li>

<li>
<label class="cartalog_label" for="options-item_modal">Modal Detail Display</label>
<input class="cartalog_input" type="checkbox" <?php if ($args['item_modal'] === '1') : echo 'checked="checked" '; endif; ?> id="options-item_modal" name="options[item_modal]" value="1" />
</li>


<li>
<label class="cartalog_label" for="options-ui_theme">jQuery UI Theme</label>
<select id="options-ui_theme" name='options[ui_theme]'>
<?php
    foreach($ui_themes as $name => $value){
        if($value === $args['ui_theme']){
            $selected = "selected";
        }
        else {
            $selected = "";
        }
?>
    <option value="<?php echo $value?>" <?php echo $selected?>><?php echo $name?></option>
<?php
    } ?>
</select>
</li>



            </ul>
          </div>
        </div>
      </div>
            <p>* Required</p>


<div class="submit">
<input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" />
</div>
        </div>
      </div>

</form>
