<?php
include('views/_header.tpl.php');

if (isset($_GET['app'])) {
    require('views/admin/app-tab.tpl.php');
    exit;
}

?>

<!--<script>
var $= jQuery.noConflict();
</script>
-->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" integrity="sha384-+d0P83n9kaQMCwj8F4RJB66tzIwOKmrdb46+porD/OvrJ+37WqIM7UoBtwHO6Nlg" crossorigin="anonymous">

<link href='//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800' rel='stylesheet' type='text/css'>

<style type="text/css">
strong {
	font-weight: bold;
}
#mmen { display:none; }
div.spacer { padding-top: 65px; }

.ajax-content {
    border: 1px solid #d4d4d4;
    background: #FFF;
    border-radius: 0 4px 4px;
    -moz-border-radius: 0 4px 4px;
    -webkit-border-radius: 0 4px 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    -moz-box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    -webkit-box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.ajax-content .loading {
    padding: 20px;
}
    
#fb-editor p {
    margin-right: 5px;
    display: inline-block;
}

#customAjaxLoader td, #customAjaxLoader th {
    padding: 4px;
}
.admintable td, .admintable th {
    padding: 3px;
    border: solid #eee 1px;
}
.regl a, .regl a:active, .regl. a:visited, .regl:link { color:#0077cc !important; }
.regl a:hover { color:#0000ff; }
/*.btn { background:#325fac; }*/
a.lgbtn, a.lgbtn:active, a.lgbtn:visited {
    padding:3px; width:50px;    display:inline-block; background:#ddd; text-shadow:0px 1px 0px #fff;
    border-radius: 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px;
}
a.lgbtn.confirm { color:#ff0000; }

a.lgbtn:hover {
    background:#0077cc; color:#fff; border-radius: 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px;
    text-shadow:0px -1px 0px rgba(0,0,0,.5);
}
a:focus {
    outline: none;
    text-decoration:none !important;
    border:0;
    color: none !important;
}
.btn-green { font-weight:normal; padding:5px 16px; }

.btn-blue { margin:5px 5px 5px 5px;  min-width:150px; font-size:17px; font-weight:300; }
.btn-red { font-size:17px; }
input[type="button"] { }
input[type="submit"] { margin:5px 5px 5px 5px; line-height:25px !important; padding-bottom:5px; width:150px; font-size:17px; }

/* ############################## */
/* #########   NAV TABS   ####### */
/* ############################## */

.nav-tabs > li.active > a {
    /*color: #377ae8;*/
    color:#ff0000;
    font-weight:bold;
    /*border: 0px solid #d4d4d4;
    border-bottom-color: #fff;*/
}

.nav-tabs > li > a {
    color: #5c666b;
    font-family: 'Open Sans', sans-serif;
    font-weight: 300;
    padding: 9px 18px;
    border-radius: 4px 4px 0 0;
    -webkit-border-radius: 4px 4px 0 0;
    -moz-border-radius: 4px 4px 0 0;
    background-color: none; 
    background:none;
}

/* ############################## */
/* #########   SUB TABS   ####### */
/* ############################## */

ul.subtabs-list {
    margin: 0;
    padding: 0;
    list-style: none;
    margin-right:10px;
    width:98%;
    background:#444;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    border-radius:5px; -moz-border-radius:5px; -webkit-border-radius:5px;
    overflow:hidden;
}
ul.subtabs-list li {
    float: left;
    width:14.5%;
    padding-left:1%;
    padding-right:1%;
    margin-left: 0px;
    border-right: 1px solid #777;
    padding-top: 5px;
    padding-bottom:7px;
    font-family: 'Open Sans',sans-serif;
    font-weight:300;
    font-size: 15px;
    background: #444;
    text-shadow:0px -1px 0px rgba(0,0,0,.4);
    text-align:center;
}
ul.subtabs-list li a {
    color: #ccc;
    font-family: 'Open Sans',sans-serif;
    font-weight:300;
    display:block;
}
ul.subtabs-list li.active {
    background: #00C617;
    color:#fff;
    text-shadow:0px -1px 0px rgba(0,0,0,.4);
}
ul.subtabs-list li.active a {
    color: #fff;
    font-family: 'Open Sans',sans-serif;
    font-weight:300;
    text-shadow:0px -1px 0px rgba(0,0,0,.4);
}
div.subtab {
    display: none;
}
div.subtab.active {
    display: block;
}

div.form.form-profile { padding-top:20px; }
td img { width:100px; }

.dashtotals {
    float:right; text-align:right; font-family:'Open Sans';
}

#footer { padding-top:0px; }
.main-footer { display:none; }

/* APP INTRO PADDING TOP */
.aif { padding-top:20px; }

/* ######################### */
/*       1024px Screens      */
/* ######################### */
@media (max-width: 1024px) {
    div.form.form-profile { }
    ul.subtabs-list {
        width:95%;
    }
}

/* ######################### */
/* Layout 2-cols */
/* ######################### */

@media (max-width: 1160px) {
    .layout-2cols { width:100%; }
}   

/* ######################### */
/* Landscape phones and down */
/* ######################### */

@media screen and (max-device-width:  600px), screen and (max-width: 600px) {
    #wrapper { overflow:hidden; }
    .nav-tabs > li {    
        width: 100% !important;
        display:block;
    }   
    .nav-tabs > li.active > a {
        color:#ff0000;
        background-color: #ccc;
        background: #ccc;
    }
    .nav-tabs > li > a {    
        width: 100% !important;
        display:block;
        color: #5c666b;
        font-family: 'Open Sans', sans-serif;
        font-weight: 300;
        padding: 9px 18px;
        /*border-bottom: 3px solid #fff;
        margin-bottom: 3px;*/
        border-radius: 0 0 0 0;
        -webkit-border-radius: 0 0 0 0;
        -moz-border-radius: 0 0 0 0;
        background-color: #eee;  
        background: #eee;
    }   
}

/* ######################### */
/* Landscape phones and down */
/* ######################### */

/* @media (max-width: 480px) { */
@media screen and (max-device-width:  480px), screen and (max-width:  480px) {
    div.spacer { padding-top: 70px; }
    .layout-2cols { padding-top:3px; }
    .header-content .header-right {
        border-bottom: 0px solid #d4d4d4;
        padding-bottom: 0px;
    }
/* ############################## */
/* #########   NAV TABS   ####### */
/* ############################## */
    ul.nav.admin-tabs.nav-tabs.clearfix { display:block; background:none; }
    .nav-tabs > li {    
        height:40px;
        width: 50% !important;
        float:left;
        display: inline-block;
        overflow:hidden;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
    }   
    .nav-tabs > li:nth-child(odd) {
        /* margin-right:2%; */
    }
    .nav-tabs > li.active {
        background:none;
        width: 50% !important;
        float:left;
        display: inline-block;      
        overflow:hidden;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;      
        border-bottom:0px solid #fff !important;
     }
    .nav-tabs > li.active > a {
        color:#ff0000;
        background-color: #ccc;
        background: #ccc;
        overflow:hidden;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;     
        border-bottom:0px solid #fff !important;   
    }
    .nav-tabs > li > a {    
        /*width: 100% !important;*/
        /*display:block;*/
        color: #5c666b;
        font-family: 'Open Sans', sans-serif;
        font-weight: 300;
        /*padding: 9px 18px;*/
       /* border-bottom: 3px solid #fff;
        margin-bottom: 3px;*/
        border-radius: 0 0 0 0;
        -webkit-border-radius: 0 0 0 0;
        -moz-border-radius: 0 0 0 0;
        background-color: #eee;  
        background: #eee;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;       
    }   

/* ############################## */
/* #########     SUB TABS     ####### */
/* ############################## */

    ul.subtabs-list {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
        width:99%;
    }
    ul.subtabs-list li {
        float: left;
        width:17.7%;
        padding-left:1%;
        padding-right:1%;
        margin-left: 0px;
        border-right: 1px solid #ccc;
        font-size: 14px;
    }


    ul.nav.admin-tabs.nav-tabs {
    }
    /*
    .nav-tabs > li {
        display: inline-block;
        float:left;
        width: 32%;  
        margin-right:1%;    
        margin-bottom:4px;
      }  
      */
      /*
     .nav-tabs > li:nth-child(odd) {
        background: purple;
        width:32%;
        margin-right:1%;
    }
    */
   /*
    .nav-tabs > li:nth-child(3n) {
        width:33%;
        margin-right:0%;
    }    
    
    .nav-tabs > li.active > a {
        color:#fff;
        text-shadow:0px -1px 1px rgba(0,0,0,.5);
        font-weight:bold;
        background-color: none !important;
        background: #cd1000 !important;
        border: 0px solid #d4d4d4;
        border-bottom-color: #ff0000;
    }
    
    .nav-tabs > li > a {    
        color: #5c666b;
        font-family: 'Open Sans', sans-serif;
        font-weight: 300;
        padding: 9px 18px;
        border-radius: 4px 4px 0 0;
        -webkit-border-radius: 4px 4px 0 0;
        -moz-border-radius: 4px 4px 0 0;
        background-color: none !important;  
        background: #eee !important;
    }
    */
    /* SUBTABS WAS HERE */
   
    .dashtotals {
        font-size:11px; padding-right:3px;
        text-shadow:0px 1px 0px rgba(255,255,255,.5); font-family:'Open Sans';
    }
    .tophdrw{ display:none; }
    div.form.form-profile { padding:5px; }
    /* APP INTRO PADDING TOP */
    .aif { padding-top:5px; }
}

</style>

<script type="text/javascript">
$('body').on('click', ".subtabs-list li a", function(e) {
        e.preventDefault();
        group_id = $(this).attr("href");
        li_elm   = $(this).parent();

        $(".subtab.active").fadeOut("fast");
        $(".subtab.active").removeClass("active");
        $(".subtabs-list li.active").removeClass("active");

        $(group_id).fadeIn("slow");
        $(group_id).addClass("active");

        li_elm.addClass("active");

        return false;
});
</script>

    <div class="layout-2cols">
        <div class="content grid_12" style="overflow:hidden;">
            <div class="project-detail" style="width:auto; overflow:hidden;">
                <div class="project-tab-detail tabbable accordion" style="width:auto; overflow:hidden;">
					<!-- $tabs = ['welcome','settings','testimonials','managelogos','featuredcontent','blogcategories','managepages','manageusers','portfolio','app-tab']; -->
                    <?php
					$invalid_tab = !in_array($_GET['tab'], ['welcome','settings','testimonials','featuredcontent','blogcategories','managelogos','managepages','app-tab','manageusers','portfolio','managepagez']);
                    $_GET['tab']       = $invalid_tab ? "welcome" : $_GET['tab'];
                    $active_welcome    = $_GET['tab'] && $_GET['tab'] == 'welcome' ? " active" : "";
                    $active_settings   = $_GET['tab'] && $_GET['tab'] == 'settings' ? " active" : "";
                    $active_testimonials   = $_GET['tab'] && $_GET['tab'] == 'testimonials' ? " active" : "";
					$active_projects   = $_GET['tab'] && $_GET['tab'] == 'featuredcontent' ? " active" : "";
					$active_projectcat = $_GET['tab'] && $_GET['tab'] == 'blogcategories' ? " active" : "";
					$active_logos      = $_GET['tab'] && $_GET['tab'] == 'managelogos' ? " active" : "";          
					
					$active_content    = $_GET['tab'] && $_GET['tab'] == 'managepages' ? " active" : "";
					$active_app        = $_GET['tab'] && $_GET['tab'] == 'app-tab' ? " active" : "";
                    $active_manageusers   = $_GET['tab'] && $_GET['tab'] == 'manageusers' ? " active" : "";
                    $active_portfolio  = $_GET['tab'] && $_GET['tab'] == 'portfolio' ? " active" : "";
					$active_pagez  = $_GET['tab'] && $_GET['tab'] == 'managepagez' ? " active" : "";
                    ?>

                    <ul class="nav admin-tabs nav-tabs clearfix">
                      <li tab="welcome" class="<?= $active_welcome ?>"><a href="#">Home</a></li>
                      <?php if ($_SESSION['loggedin'] && $_SESSION['user']['is_admin'] < 3) : ?>
					  	<li tab="settings" class="<?= $active_settings ?>"><a href="#">Design</a></li> 
						<li tab="testimonials" class="<?= $active_testimonials ?>"><a href="#">Testimonials</a></li> 
						<li tab="featuredcontent" class="<?= $active_projects ?>"><a href="#">Featured</a></li>
						<li tab="blogcategories" class="<?= $active_projectcat ?>"><a href="#">Categories</a></li>
						<li tab="managelogos" class="<?= $active_logos ?>"><a href="#">Logos</a></li>
						<li tab="managepages" class="<?= $active_content ?>"><a href="#">CMS Pages</a></li>
						<li tab="app-tab" class="<?= $active_app ?>"><a href="#">SubTabs</a></li>
						<li tab="manageusers" class="<?= $active_manageusers ?>"><a href="#">Users</a></li>
						<!--<li tab="portfolio" class="<?= $active_portfolio ?>"><a href="#">Folio</a></li>-->
						<li tab="managepagez" class="<?= $active_pagez ?>"><a href="#">Solutions</a></li>
                      <?php endif; ?>
                    </ul>
                    
                    <script>
                    $('.admin-tabs li').click(function () {
                        var tab = $(this).attr('tab');
                        $('.ajax-content').fadeTo( 'fast', 0.8 );
                        if (tab) {           
                            $.ajax({
                                data: {
                                    tab: tab
                                },
                                success: function (d) {
                                    $('.ajax-content').fadeTo( 1, 1 );
                                    $('.ajax-content').html(d);
                                }
                            });
                        }
                    });
                    </script>
                    
                    <div class="ajax-content">
                        <?php
                        // load initial tab directly
                        require('views/admin/tabs/welcome.tpl.php');
                        ?>                          
                    </div>

                </div><!--end: .project-tab-detail -->
            </div>
        </div><!--end: .content grid_12 -->
        <div class="clear"></div>
    </div><!-- END OF 2 COLS LAYOUT -->

<script src="/3rdparty/ckeditoradv/ckeditor.js?<?php echo rand() ?>"></script>
<script>
	//alert('hi');
		
// $('.featured').change(function () {
$('body').on( 'click', '.featured', function (e) {
    $.ajax({
        async: true,
        url: '?setFeatured',
        type: 'post',
        data: {
            id: $(this).attr('id'),
            flag: ($(this).attr('flag')),
            featured: ($(this).attr('checked') == 'checked')
        },
        success: function (d) {
            if (d != 'ok') {
                alert("Unable to update featured status");
            }
        }
    })
});

// FULFILLED AJAX WAS HERE
$('body').on( 'click', '.todayPay', function (e) {
    $.ajax({
        async: true,
        url: '?todayPay',
        type: 'post',
        data: {
            id: $(this).attr('id'),
            value: ($(this).attr('value')),
        },
        success: function (d) {
            if (d != 'ok') {
                alert("Unable to update amount_paid ");
            }
        }
    })
});

$('body').on( 'click', '.activate-user', function (e) {
    e.preventDefault();

    var button = $(this);
    var row    = $(this).parents("tr").first();
    var uid    = row.attr("data-uid");
    var url    = $(this).attr("href");
    $.ajax({
        async: true,
        url: url,
        type: "post",
        data: {uid: uid},
        success:function(d) {
            var d = eval(d);

            if (d)
                // activate done.
                row.fadeOut();
                //alert('This User Account has been activated.');
                $('[tab=manageusers]').click(); // reload tab
        }
    });
    return false;
});

$('body').on( 'click', '.delete-user', function (e) {
    e.preventDefault();

    var button = $(this);
    var row    = $(this).parents("tr").first();
    var uid    = row.attr("data-uid");
    var url    = $(this).attr("href");
    $.ajax({
        async: true,
        url: url,
        type: "post",
        data: {uid: uid},
        success:function(d) {
            var d = eval(d);

            if (d)
                // activate done.
                row.fadeOut();
                alert('This User Account has been deleted.');
                $('[tab=manageusers]').click(); // reload tab
        }
    });
    return false;
});

$('body').on( 'click', '.make-admin', function (e) {
    e.preventDefault();

    var button = $(this);
    var row    = $(this).parents("tr").first();
    var uid    = row.attr("data-uid");
    var url    = $(this).attr("href");
    $.ajax({
        async: true,
        url: url,
        type: "post",
        data: {uid: uid},
        success:function(d) {
            var d = eval(d);

            if (d)
                // activate done.
                //row.fadeOut();
                alert('This User has been updated to an Admin.');
                $('[tab=manageusers]').click(); // reload tab
        }
    });
    return false;
});

$('body').on( 'click', '.remove-admin', function (e) {
    e.preventDefault();

    var button = $(this);
    var row    = $(this).parents("tr").first();
    var uid    = row.attr("data-uid");
    var url    = $(this).attr("href");
    $.ajax({
        async: true,
        url: url,
        type: "post",
        data: {uid: uid},
        success:function(d) {
            var d = eval(d);

            if (d)
                // activate done.
                //row.fadeOut();
                alert('Admin priveleges have been removed.');
                $('[tab=manageusers]').click(); // reload tab
                //location.window.href = "/admin/?tab=usersact";
        }
    });
    return false;
});

// TOGGLE SQUARE CATEGORIES HIDDEN FIELD ON/OFF
$('body').on( 'click', '.slider', function (e) {
    e.preventDefault();
    //$("input:checkbox").on("change", function () {
    //var val = $(this).val();
   // var apply = $(this).is(':checked') ? 1 : 0;
    //var button = $(this);
     //var checked = $(this).is(':checked') ? 1 : 0;
    var row    = $(this).parents("tr").first();
    var id    = row.attr("data-id");     
    var checked =  row.attr("data-checked"); 
    var checkStatus = $(this).checked ? 'ON' : 'OFF';
    //var checked = $('.hiddenval').val();
    //var id    = $(this).attr("data-id");
   // var id    = switch.attr("data-id");
    $.ajax({
        async: true,
        url: '/admin/makeHidden',
        type: "post",
        data: {id: id, checked:checked},
        success:function(d) {
            var d = eval(d);

            if (d){
                alert('This item has been updated! Saving...');
               // $('#resultQuickVar1').html(data);
                //alert('This item has been updated! id is: ' + id + ' and checkedval is: ' + checked + ' and d is: ' + d);
                //$(".is_excludeddiv").load(" .is_excludeddiv");
                //$('.is_excludeddiv').html(d);
                $('[tab=squarecats]').click(); // reload tab                
            } else {
                alert('This item has been updated! Saving...');
                //alert('Hidden! id is: ' + id + ' and checkedval is: ' + checked + ' and d is: ' + d);
                //$(".is_excludeddiv").load(" .is_excludeddiv");
                //$('.is_excludeddiv').html(d);
                $('[tab=squarecats]').click(); // reload tab    
            }
        }
    });
    return false;
});

// TOGGLE SQUARE LOCATIONS HIDDEN FIELD ON/OFF
$('body').on( 'click', '.sliderloc', function (e) {
    e.preventDefault();
    //$("input:checkbox").on("change", function () {
    //var val = $(this).val();
   // var apply = $(this).is(':checked') ? 1 : 0;
    //var button = $(this);
     //var checked = $(this).is(':checked') ? 1 : 0;
    var row    = $(this).parents("tr").first();
    var id    = row.attr("data-id");     
    var checked =  row.attr("data-checked"); 
    var checkStatus = $(this).checked ? 'ON' : 'OFF';
    //var checked = $('.hiddenval').val();
    //var id    = $(this).attr("data-id");
   // var id    = switch.attr("data-id");
    $.ajax({
        async: true,
        url: '/admin/makeHiddenLocation',
        type: "post",
        data: {id: id, checked:checked},
        success:function(d) {
            var d = eval(d);

            if (d){
                alert('This item has been updated! Saving...');
               // $('#resultQuickVar1').html(data);
                //alert('This item has been updated! id is: ' + id + ' and checkedval is: ' + checked + ' and d is: ' + d);
                //$(".is_excludeddiv").load(" .is_excludeddiv");
                //$('.is_excludeddiv').html(d);
                $('[tab=squarelocs]').click(); // reload tab                
            } else {
                alert('This item has been updated! Saving...');
                //alert('Hidden! id is: ' + id + ' and checkedval is: ' + checked + ' and d is: ' + d);
                //$(".is_excludeddiv").load(" .is_excludeddiv");
                //$('.is_excludeddiv').html(d);
                $('[tab=squarelocs]').click(); // reload tab    
            }
        }
    });
    return false;
});


$(function() {  
	CKEDITOR.config.extraPlugins = 'justify', 'imgbrowse','ckeditor-gwf-plugin';   
    CKEDITOR.add
    CKEDITOR.config.contentsCss = '/static/css/my_styles.css';  
    CKEDITOR.config.font_names = 'GoogleWebFonts';    
});
</script>

<style>
	.admintable td, .admintable th {
	    padding: 3px;
	    border:solid #eee 1px;
	}
	.cke_editable strong, strong.cke_editable {
		font-weight:800 !important;
	}
	strong, p strong {
		font-weight: 800;
	}
	@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;500;600;700;800&display=swap');
</style>

<?php
include 'views/_footer_m.tpl.php';
?>