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

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

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

?>

<style type="text/css">
.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-blue { margin:5px 5px 5px 0; }

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

.nav-tabs > li.active > a {
    /*color: #377ae8;*/
	color:#ff0000;
	font-weight:bold;
    background-color: none !important;
	background:none !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:none !important;
}

/* ############################## */
/* #########   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; }
}

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

@media screen and (max-device-width:  480px), screen and (max-width:  480px) {
	.layout-2cols { padding-top:3px; }
	.header-content .header-right {
		border-bottom: 0px solid #d4d4d4;
		padding-bottom: 0px;
	}
	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:14%;
		padding-left:1%;
		padding-right:1%;
		margin-left: 0px;
		border-right: 1px solid #777;
		font-size: 14px;
	}
	.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;">

                    <?php
                    $invalid_tab = !in_array($_GET['tab'], ['welcome','settings', 'orders', 'testimonials', 'logos', 'projects', 
															'storecat', 'projectcat', 'content',  'app', 'jets', 'manageusers',
                                                            'appintro', 'portfolio', 'forms']);
                    $_GET['tab'] 	   = $invalid_tab ? "welcome" : $_GET['tab'];
					$active_welcome    = $_GET['tab'] && $_GET['tab'] == 'welcome' ? " active" : "";
                    $active_settings   = $_GET['tab'] && $_GET['tab'] == 'settings' ? " active" : "";
					$active_orders     = $_GET['tab'] && $_GET['tab'] == 'orders' ? " active" : "";
					$active_testimonials   = $_GET['tab'] && $_GET['tab'] == 'testimonials' ? " active" : "";
					$active_logos	   = $_GET['tab'] && $_GET['tab'] == 'logos' ? " active" : "";
                    $active_projects   = $_GET['tab'] && $_GET['tab'] == 'projects' ? " active" : "";
                    $active_storecat   = $_GET['tab'] && $_GET['tab'] == 'storecat' ? " active" : "";
                    $active_projectcat = $_GET['tab'] && $_GET['tab'] == 'projectcat' ? " active" : "";
                    $active_content    = $_GET['tab'] && $_GET['tab'] == 'content' ? " active" : "";
					$active_app   	   = $_GET['tab'] && $_GET['tab'] == 'app' ? " active" : "";
					$active_jets   	   = $_GET['tab'] && $_GET['tab'] == 'jets' ? " active" : "";
					$active_manageusers   = $_GET['tab'] && $_GET['tab'] == 'manageusers' ? " active" : "";
                    $active_appintro   = !$_GET['tab'] || $_GET['tab'] == 'appintro' ? " active" : "";
                    $active_portfolio  = $_GET['tab'] && $_GET['tab'] == 'portfolio' ? " active" : "";
                    $active_forms  = $_GET['tab'] && $_GET['tab'] == 'forms' ? " active" : "";
                    ?>

					<ul class="nav admin-tabs nav-tabs clearfix">
					  <li tab="welcome" class="<?= $active_welcome ?>"><a href="#">Welcome</a></li>
					  <?php if ($_SESSION['loggedin'] && $_SESSION['user']['is_admin'] < 3) : ?>
						  <li tab="settings" class="<?= $active_settings ?>"><a href="#">Settings</a></li>
						  <li tab="orders" class="<?= $active_orders ?>"><a href="#">Orders</a></li>
						  <li tab="testimonials" class="<?= $active_testimonials ?>"><a href="#">Testimonials</a></li>
						  <li tab="managelogos" class="<?= $active_logos ?>"><a href="#">Logos</a></li>
						  <li tab="featuredcontent" class="<?= $active_projects ?>"><a href="#">Featured</a></li>
						  <li tab="manageshops" class="<?= $active_storecat ?>"><a href="#">Shop</a></li>
					  <?php endif; ?>
					  
                      <li tab="blogcategories" class="<?= $active_projectcat ?>"><a href="#">Cats</a></li>
                      <li tab="managepages" class="<?= $active_content ?>"><a href="#">CMS</a></li>

					  <?php if ($_SESSION['loggedin'] && $_SESSION['user']['is_admin'] < 3) : ?>
					      <li tab="app-tab" class="<?= $active_app ?>"><a href="#">App</a></li>		
						  <li tab="jets" class="<?= $active_jets ?>"><a href="#">Jets</a></li>
						  <li tab="manageusers" class="<?= $active_manageusers ?>"><a href="#">Users</a></li>
						  <li tab="welcomeslides" class="<?= $active_appintro ?>"><a href="#">Intro</a></li>
						  <li tab="portfolio" class="<?= $active_portfolio ?>"><a href="#">Portfolio</a></li>
						  <li tab="forms" class="<?= $active_forms ?>"><a href="#">Forms</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>

					<!-- I'M NOT SURE WE EVEN NEED ALL THESE SECTIONS ANY MORE -->
					
                    <div class="tab-content" style="padding-top:0px; margin-top:0px !important;">
                        <div style="padding-top:0px; margin-top:0px !important;">
						
                            <h3 class="rs alternate-tab accordion-label">Welcome <i class="fa fa-caret-down" style="float:right; margin:3px 5px 0 5px;"></i></h3>
                            <div class="tab-pane accordion-content<?= $active_welcome ?>">                             
								<div class="clear"></div>                            
							</div>
                            <div class="clear"></div>

						</div><!-- END OF WELCOME DIV --><!--end: .tab-pane (Website Welcome) -->

						<!-- ###################################### -->
						<!-- ###########    SETTINGS    ########### -->
						<!-- ###################################### -->
						
                        <div>						
						
                            <h3 class="rs alternate-tab accordion-label">Settings <i class="fa fa-caret-down" 
							style="float:right; margin:3px 5px 0 5px;"></i></h3>
                            
                            <div class="tab-pane accordion-content">
                            </div>
                        </div>
						
						<!-- ########################## -->
						<!--  NEW ORDERS SECTION  -->
						<!-- ########################## -->								
						
                        <div>
                            <h3 class="rs alternate-tab accordion-label">New Orders <i class="fa fa-caret-down" style="float:right; margin:3px 5px 0 5px;"></i></h3>
                            <div class="tab-pane accordion-content<?= $active_orders ?>">
                            </div><!--end: .tab-pane (Featured) -->
                        </div>		

						<!-- ############################### -->
						<!--   MANAGE TESTIMONIALS SECTION   -->
						<!-- ############################### -->								
						
                        <div>
							<h3 class="rs alternate-tab accordion-label">Testimonials <i class="fa fa-caret-down" style="float:right; margin:3px 5px 0 5px;"></i></h3>
                            <div class="tab-pane accordion-content<?= $active_testimonials ?>" style="padding:30px">
                            </div><!--end: .tab-pane (Blog Categories) -->
                        </div>						
						
						<!-- ########################## -->
						<!--    MANAGE LOGOS SECTION    -->
						<!-- ########################## -->								
						
                        <div>
							<h3 class="rs alternate-tab accordion-label">Logos <i class="fa fa-caret-down" style="float:right; margin:3px 5px 0 5px;"></i></h3>
                            <div class="tab-pane accordion-content<?= $active_logos ?>" style="padding:30px">
                            </div><!--end: .tab-pane (Blog Categories) -->
                        </div>							
												
						<!-- ########################## -->
						<!--  FEATURED CONTENT SECTION  -->
						<!-- ########################## -->								
						
                        <div>
                            <h3 class="rs alternate-tab accordion-label">Featured <i class="fa fa-caret-down" style="float:right; margin:3px 5px 0 5px;"></i></h3>
                            <div class="tab-pane accordion-content<?= $active_projects ?>">
                            </div><!--end: .tab-pane (Featured) -->
                        </div>
                        <!-- <div>
                            <div class="tab-pane accordion-content">
                                Categories
                            </div>
                        </div>
                        -->

						<!-- ########################## -->
						<!--    MANAGE SHOP SECTION     -->
						<!-- ########################## -->								
						
                        <div>
							<h3 class="rs alternate-tab accordion-label">Shop Categories<i class="fa fa-caret-down" style="float:right; margin:3px 5px 0 5px;"></i></h3>
							<div class="tab-pane accordion-content<?= $active_storecat ?>" style="padding:30px;">
							</div><!--end: .tab-pane (Store Categories) -->
                        </div>
						
						<!-- ########################## -->
						<!-- MANAGE CATEGORIES SECTION  -->
						<!-- ########################## -->								
						
                        <div>
							<h3 class="rs alternate-tab accordion-label">Categories <i class="fa fa-caret-down" style="float:right; margin:3px 5px 0 5px;"></i></h3>
                            <div class="tab-pane accordion-content<?= $active_projectcat ?>">
                            </div><!--end: .tab-pane (Blog Categories) -->
                        </div>

						<!-- ########################## -->
						<!--   MANAGE PAGES SECTION  	-->
						<!-- ########################## -->		
						
                        <div>
						    <h3 class="rs alternate-tab accordion-label">Manage Pages <i class="fa fa-caret-down" style="float:right; margin:3px 5px 0 5px;"></i></h3>
                            <div class="tab-pane accordion-content<?= $active_content ?>">
                            </div><!--end: .tab-pane (Manage Pages) -->
                        </div>

                        <!-- ##################### -->
						<!--  MOBILE APP SECTION -->
						<!-- ########################## -->
						<div> 
                            <h3 class="rs alternate-tab accordion-label">App <i class="fa fa-caret-down" style="float:right; margin:3px 5px 0 5px;"></i></h3>
                            <div class="tab-pane accordion-content<?= $active_app ?>">
    						<?php
//                             require('views/admin/tabs/app-tab.tpl.php');
                            ?>    						
                            </div><!--end: .tab-pane (Manage Pages) -->
                        </div>

  
                        <!-- ##################### -->
						<!-- NEW JETS SECTION -->
						<!-- ########################## -->
						<div>
                            <h3 class="rs alternate-tab accordion-label">Jets <i class="fa fa-caret-down" style="float:right; margin:3px 5px 0 5px;"></i></h3>
                            <div class="tab-pane accordion-content<?= $active_jets ?>"></div>
                        </div>

						<!-- ########################## -->
						<!-- MANAGE USERS SECTION -->
						<!-- ########################## -->		

                        <div>
                            <h3 class="rs alternate-tab accordion-label">Manage Users <i class="fa fa-caret-down" style="float:right; margin:3px 5px 0 5px;"></i></h3>
                            <div class="tab-pane accordion-content<?= $active_manageusers ?>"></div>
                        </div>

						<!-- ########################## -->
						<!--  APP INTRO/WELCOME SLIDES  -->
						<!-- ########################## -->								

                        <div>
                            <h3 class="rs alternate-tab accordion-label">App Intro Slides <i class="fa fa-caret-down" 
							style="float:right; margin:3px 5px 0 5px;"></i></h3>
                            <div class="tab-pane accordion-content<?= $active_appintro ?>" style="overflow:hidden;">
                            </div><!--end: .tab-pane (App Intro/Sliders)-->
                        </div>

						<!-- ########################## -->
						<!-- PORTFOLIO GALLERY SECTION  -->
						<!-- ########################## -->							
					
                        <div>
                            <h3 class="rs alternate-tab accordion-label">Portfolio Gallery <i class="fa fa-caret-down" style="float:right; margin:3px 5px 0 5px;"></i></h3>
                            <div class="tab-pane accordion-content<?= $active_portfolio ?>" style="overflow:hidden;">
                            </div><!--end: .tab-pane (Portfolio) -->
                        </div>
                        
                        <!-- ####### -->
						<!--  FORMS  -->
						<!-- ####### -->								

                        <div>
                            <h3 class="rs alternate-tab accordion-label">Forms <i class="fa fa-caret-down" 
							style="float:right; margin:3px 5px 0 5px;"></i></h3>
                            <div class="tab-pane accordion-content<?= $active_appintro ?>" style="overflow:hidden;">
                            </div><!--end: .tab-pane -->
                        </div>

                    </div><!-- END OF TAB CONTENT -->

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

<script>
$('.featured').change(function () {
    $.ajax({
        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').change(function () {	
	var ischecked = $(this).is(':checked');
    if(!ischecked){
		$.ajax({
			url: '?setFulfilled',
			type: 'post',
			data: {
				id: $(this).attr('id'),
				flag: ($(this).attr('flag')),
				fulfilled: ($(this).attr('checked') == '')
			},
			success: function (d) {
				$('#ostatus').html('<span style="color:#ff0000;">Unfulfilled</span>');
				if (d != 'ok') {
					alert("Unable to update fulfillment status");
				}
			}
		})			
	} else {
		$.ajax({
			url: '?setFulfilled',
			type: 'post',
			data: {
				id: $(this).attr('id'),
				flag: ($(this).attr('flag')),
				fulfilled: ($(this).attr('checked') == 'checked')
			},
			success: function (d) {
				$('#ostatus').html('<span style="color:#38BC00;">Fulfilled</span>');
				if (d != 'ok') {
					alert("Unable to update fulfillment status");
				}
			}
		})		
	}
});

$('.todayPay').change(function () {
    $.ajax({
        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 ");
            }
        }
    })
});

$(".activate-user").click(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({
        url: url,
        type: "post",
        data: {uid: uid},
        success:function(d) {
            var d = eval(d);

            if (d)
                // activate done.
                row.fadeOut();

        }
    });
    return false;
});

$(".user-fees").each(function()
{
    var href = $(this).attr("href");
    $(this).fancybox({
        'hideOnContentClick': true,
        'width': 1200,
        'height': 550,
        'autoDimensions': false,
        'autoSize': false,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 500,
        'speedOut': 300,
        'centerOnScroll': true,
        'type': 'ajax',
        'href': href
    });
});

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

<style>
.admintable td, .admintable th {
    padding: 3px;
    border:solid #eee 1px;
}
</style>
<?php
include 'views/_footer.tpl.php';
?>
<!--
6/29/2017 - I commented this out because for some reason it was 
hanging the whole admin update, but I need these so hopefully we can 
just split the Admin up more so only the things needed for the area 
that's needed to be updated can simply be loaded - instead of having 
to load everything.

<script src="/3rdparty/ckeditoradv/ckeditor.js"></script>

<script>
CKEDITOR.replace( 'ckeditor1' ,{
	filebrowserBrowseUrl : '/filemanager/dialog.php?type=2&editor=ckeditor&fldr=',
	filebrowserUploadUrl : '/filemanager/dialog.php?type=2&editor=ckeditor&fldr=',
	filebrowserImageBrowseUrl : '/filemanager/dialog.php?type=1&editor=ckeditor&fldr='
});
</script>

<script>
CKEDITOR.replace( 'ckeditor2' ,{
	filebrowserBrowseUrl : '/filemanager/dialog.php?type=2&editor=ckeditor&fldr=',
	filebrowserUploadUrl : '/filemanager/dialog.php?type=2&editor=ckeditor&fldr=',
	filebrowserImageBrowseUrl : '/filemanager/dialog.php?type=1&editor=ckeditor&fldr='
});
</script>

<script>
CKEDITOR.replace( 'ckeditor3' ,{
	filebrowserBrowseUrl : '/filemanager/dialog.php?type=2&editor=ckeditor&fldr=',
	filebrowserUploadUrl : '/filemanager/dialog.php?type=2&editor=ckeditor&fldr=',
	filebrowserImageBrowseUrl : '/filemanager/dialog.php?type=1&editor=ckeditor&fldr='
});
</script>

<script>
CKEDITOR.replace( 'ckeditor4' ,{
	filebrowserBrowseUrl : '/filemanager/dialog.php?type=2&editor=ckeditor&fldr=',
	filebrowserUploadUrl : '/filemanager/dialog.php?type=2&editor=ckeditor&fldr=',
	filebrowserImageBrowseUrl : '/filemanager/dialog.php?type=1&editor=ckeditor&fldr='
});
</script>

<script>
CKEDITOR.replace( 'ckeditor5' ,{
	filebrowserBrowseUrl : '/filemanager/dialog.php?type=2&editor=ckeditor&fldr=',
	filebrowserUploadUrl : '/filemanager/dialog.php?type=2&editor=ckeditor&fldr=',
	filebrowserImageBrowseUrl : '/filemanager/dialog.php?type=1&editor=ckeditor&fldr='
});
</script>

-->