<?php
/*
Plugin Name: Modify Homepage
Description: Customizes the page users see after logging in to CMS Builder
Version: 1.00
Requires at least: 2.06
*/

// READ BELOW TO CUSTOMIZE THIS PLUGIN

// To disable the home page completely, uncomment this next line and supply a URL to redirect to (e.g. '?menu=_myaccount')
//$GLOBALS['MODIFY_HOMEPAGE_REDIRECT_QUERY'] = '?menu=_myaccount'; // query string to use instead of home page

// To customize the home page's title, modify the HTML between the > < below

  require_once "lib/menus/default/list_functions.php";
  
if(@$_REQUEST['recordLimit']){
    
    if($_REQUEST['section']){
        include($_REQUEST['section'].'.php');
    }
    exit;
}
if(isset($_REQUEST['mapData'])){
    include('mapData.php');
    exit;
}


function modifyHomepage_title() {
  ?>
  
    Urban Halal Dashboard
  
  <?php
}

// To customize the home page's content, modify the HTML between the > < below
function modifyHomepage_content() {

    $stats        = mysql_get('dashboard_stats', 1);

    $recentUser   = mysql_get("members", null, "TRUE ORDER BY createdDate DESC", "`num`, `username`, `points`, `facebook_picture`, `total_shares`");

    $userInvites  = mysql_count("pending_invite_messages", "`membersNum` = {$recentUser['num']}");

    
    $openedCount  = mysql_count("_nlb_log", "`eventNum` = 5");

    

    $clickedCount  = mysql_count("_nlb_log", "`eventNum` = 6");

    $unsubCount  = mysql_count("_nlb_log", "`eventNum` = 3");

   // echo $openCount; exit();

  global $CURRENT_USER;

    
    $limit = 100;
    $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
    $start = ($page - 1) * $limit;

    $currentListing = mysql_get("listings", null, "`createdByUserNum` = {$CURRENT_USER['num']}", "`num`, `is_online`, `offline_record_time`, `timezone`");

    $where = "order_status IN ('delivered','cancelled','refunded')";
    if(!$CURRENT_USER['isAdmin']) {
      $where .= " AND `listingsNum` = {$currentListing['num']}";
    }elseif (isset($_REQUEST["listingsNum"]) && !empty($_REQUEST["listingsNum"])) {
      $where .= " AND `listingsNum` = {$_REQUEST["listingsNum"]}";
    }
    
    $where1 = $dateWhere = "TRUE";
    if(isset($_REQUEST["toDate"]) && !empty($_REQUEST["toDate"])) {
      $labelToDate = $_REQUEST["toDate"];
      $formatDate = explode("-", $labelToDate);
      $toDate   = $formatDate[2] . "-" . $formatDate[0] . "-" . $formatDate['1'];
    }else{
      $labelToDate = date('m-d-Y');
      $toDate    = date('Y-m-d');
    }

    if(isset($_REQUEST["fromDate"]) && !empty($_REQUEST["fromDate"])) {
      $labelFromDate = $_REQUEST["fromDate"];
      $formatDate = explode("-", $labelFromDate);
      $fromDate   = $formatDate[2] . "-" . $formatDate[0] . "-" . $formatDate['1'];
    }else{
      $fromDate   = date("Y-m-d", strtotime($toDate . "-60 days"));
      $formatDate = explode("-", $fromDate);
      $labelFromDate = $formatDate[1] . "-" . $formatDate[2] . "-" . $formatDate['0'];
    }

    if(isset($_REQUEST["changeDate"]) && !empty($_REQUEST["changeDate"])){
      if($_REQUEST["changeDate"] == 1){
        $labelToDate = $toDate = date("m-d-Y", strtotime($labelToDate . "+6 days"));
        $labelFromDate = $fromDate = date("m-d-Y", strtotime($labelFromDate . "+6 days"));
      }elseif($_REQUEST["changeDate"] == -1){
        $labelToDate = $toDate = date("m-d-Y", strtotime($labelToDate . "-6 days"));
        $labelFromDate = $fromDate = date("m-d-Y", strtotime($labelFromDate . "-6 days"));
      }
    }

    if(isset($fromDate, $toDate) && !empty($fromDate) && !empty($toDate)){
      $dateWhere .= " AND `createdDate` >= '".$fromDate." 00:00:00' AND `createdDate` <= '".$toDate." 23:59:59'";
    }

    $sortWhere = (isset($_REQUEST["orderSort"]) && !empty($_REQUEST["orderSort"])) ? $_REQUEST["orderSort"] : "";

    $chartData = [];

    $chartOrders = mysql_select("orders", "$dateWhere AND $where GROUP BY DATE_FORMAT(`createdDate`, '%Y-%m-%d')", "`createdDate`, count(num) as order_count");

    foreach($chartOrders as $chartOrder) { 
                                            
      $chartData[] = [
        'date' => date("n/j", strtotime($chartOrder['createdDate'])),
        'count' => $chartOrder['order_count']
      ];
    }

    $orders = mysql_select("orders","$dateWhere AND $where ORDER BY `createdDate` DESC LIMIT $start, $limit");

    if(isset($sortWhere) && !empty($sortWhere)){
      $orders = mysql_select("orders","$dateWhere AND $where ORDER BY $sortWhere LIMIT $start, $limit");
    }

    $orderCount = mysql_count("orders","$dateWhere AND $where");
    $metaData= [];
    $total = $orderCount;
  
    $pages = ceil( $total / $limit );

    $metaData = [
      'perPage' => $limit,
      'page' => $page,
      'totalPages' => $pages
    ];

    if($CURRENT_USER['isAdmin']) {
      $cancelledOrderCount = mysql_count("orders","$dateWhere AND $where AND `order_status` IN ('refunded', 'cancelled')");
      $allOrders = mysql_select("orders","$dateWhere AND $where ORDER BY `createdDate` DESC");
    }else{
      $cancelledOrderCount = mysql_count("orders","$dateWhere AND `listingsNum` = {$currentListing['num']} AND `order_status` IN ('refunded', 'cancelled')");
      $allOrders = mysql_select("orders","$dateWhere AND `listingsNum` = {$currentListing['num']} ORDER BY `createdDate` DESC");
    }
    
    $deliveredOrderCount = $orderCount - $cancelledOrderCount;

    $refundedAmount = $totalAmount = $refundTip = $deliverTip = 0;
    foreach ($allOrders as $oneOrder) {

      //$tip += $oneOrder['service_tip'];

      if((strtolower($oneOrder['order_status'])=='cancelled')){

        $refundTip += $oneOrder['service_tip'];

        if(!$CURRENT_USER['isAdmin']) {
          $refundedAmount += calculateOrderTotal($oneOrder);
        }
        else{
          $refundedAmount += $oneOrder['total'];
        }
      }
      else if((strtolower($oneOrder['order_status'])=='refunded')){

        $refundTip += $oneOrder['service_tip'];

        if(!$CURRENT_USER['isAdmin']) {
          $refundedAmount += calculateOrderTotal($oneOrder);
        }else{
          $refundedAmount += $oneOrder['refund_amount'];
        }
      }
      elseif(strtolower($oneOrder['order_status'])=='delivered'){

        $deliverTip += $oneOrder['service_tip'];

        if(!$CURRENT_USER['isAdmin']) {
          $totalAmount += calculateOrderTotal($oneOrder);
        }
        else{
          $totalAmount += $oneOrder['total'];
        }
      }
    }


    $totalTip = $refundTip + $deliverTip;

    $totalCount = $deliveredOrderCount + $cancelledOrderCount;

    if(isset($totalCount) && !empty($totalCount)){

    $avgCart = ($refundedAmount + $totalAmount) / ($totalCount);

  }

  if($CURRENT_USER['isAdmin']) {
    /// show listing record on listing select
    $listings = mysql_select_query("SELECT num, CONCAT(name,'-',zip) name, address_1, city, state, zip FROM `urbanhal_listings` WHERE `enable_order` = 1 ORDER BY name ASC");
  }
    // print_r($dateWhere);
    // print_r($where);
    // print_r($orders);die;

  $toDate1 = (isset($_REQUEST["toDate"]) && !empty($_REQUEST["toDate"])) ? $_REQUEST["toDate"] : date("m-d-Y");

  $fromDate1 = (isset($_REQUEST["fromDate"]) && !empty($_REQUEST["fromDate"])) ? $_REQUEST["fromDate"] : date('m-d-Y', strtotime(str_replace('-', '/', $toDate) . "-150 days"));
  if(isset($fromDate1, $toDate1) && !empty($fromDate1) && !empty($toDate1)){
    $where1 .= " AND DATE_FORMAT(`createdDate`, '%m-%d-%Y') BETWEEN '".$fromDate1."' AND '".$toDate1."'";
  }

  $chartData1 = [];

  $chartPayments = mysql_select("listing_payments", "$where1", "`createdDate`, `amount`");
  // print_r($chartData);
  foreach($chartPayments as $chartPayment) { 
                                          
    $chartData1[] = [
      'date' => date("j F", strtotime($chartPayment['createdDate'])),
      'count' => $chartPayment['amount']
    ];
  }

  $where = "TRUE";
  $userPayments = mysql_select("listing_payments", "$where ORDER BY createdDate DESC");

  $userPayout = $userOrder = 0;

  foreach ($userPayments as $userPayment) {

    $userPayout += $userPayment['net_payout'];

    $userOrder += $userPayment['orders_count'];
    
  }
  // print_r($chartData1);
  ?>
  <link rel="stylesheet" type="text/css" href="plugins/modifyHomepage/css/style.css">
  <!-- <script src="https://code.jquery.com/jquery-3.1.0.min.js"></script> -->
    
    <script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places&key=AIzaSyCSW36wmavfO9P6Xvx_lf_lwYLrPRQuIwc"></script>
    <!-- Resources -->
    <script src="plugins/modifyHomepage/js/amcharts4/core.js"></script>
    <script src="plugins/modifyHomepage/js/amcharts4/charts.js"></script>
    <script src="plugins/modifyHomepage/js/amcharts4/plugins/wordCloud.js"></script>
    <script src="https://www.amcharts.com/lib/amcharts.js" type="text/javascript"></script>
    <script src="plugins/modifyHomepage/js/amcharts4/themes/animated.js"></script>
    
<!--     <div class="row">
        <div class="col-md-12 col-lg-12 col-sm-12">
            <div class="database_box1" style="">
                <div class="quick_launches_wrap text-center">
                    <div class="row">
                        <div class="col-md-3 col-sm-4 col-xs-6 quick_launch">
                            <p><a href="https://aws.amazon.com/console/" target="_blank">AWS Console</a></p>
                        </div>
                        <div class="col-md-3 col-sm-4 col-xs-6 quick_launch">
                            <p><a href="https://console.aws.amazon.com/workmail/v2/home?region=us-east-1#/"  target="_blank">AWS Email</a></p>
                        </div>
                        <div class="col-md-3 col-sm-4 col-xs-6 quick_launch">
                            <p><a href="https://s3.console.aws.amazon.com/s3/home?region=us-west-1#"  target="_blank">AWS S3</a></p>
                        </div>
                        <div class="col-md-3 col-sm-4 col-xs-6 quick_launch">
                            <p><a href="https://cloudeq.atlassian.net/jira/projects"  target="_blank">Jira CloudEQ</a></p>
                        </div>
                        <div class="col-md-3 col-sm-4 col-xs-6 quick_launch">
                            <p><a href="https://developers.google.com/"  target="_blank">GCloud</a></p>
                        </div>
                        <div class="col-md-3 col-sm-4 col-xs-6 quick_launch">
                            <p><a href="https://business.facebook.com/"  target="_blank">FB Business</a></p>
                        </div>
                        <div class="col-md-3 col-sm-4 col-xs-6 quick_launch">
                            <p><a href="https://www.doordash.com/drive"  target="_blank">Doordash</a></p>
                        </div>
                        <div class="col-md-3 col-sm-4 col-xs-6 quick_launch">
                            <p><a href="https://partner.postmates.com/dashboard/home"  target="_blank">Postmates partner</a></p>
                        </div>
                    </div>
                </div>             
            </div>
        </div>
    </div> -->
    <?php 
        $array = [
          [
            "title"=> 'amazon',
            "image" => 'https://s3-us-west-1.amazonaws.com/urban-halal-stage/testing/menu/MI/Dearborn/48126/Halal-World-Depot/thumb/halal-beef-burger-patties.jpg',
            "url" => 'https://aws.amazon.com/console/',
          ],
          [
            "title"=> 'postmate',
            "image" => 'https://s3-us-west-1.amazonaws.com/urban-halal-stage/thumb/grilled-chicken-4-1200.jpg',
            "url" => 'https://partner.postmates.com/dashboard/home',
          ],
          [
            "title"=> 'Ready',
            "image" => '',
            "url" => '?_pluginAction=urbcan_updateDrivethruOrderStatus',
          ]
        ];
    ?>
    <!-- <div class="row">
      <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12">
        <div class="database_box">
          <div class="sec-ring-border-box">
            <div class="sec-ring-border-med-box">
              <div class="top-moments-section">
                <div class="moments-wrapper flex_elm" id="items-wrapper" style="padding-left: 10px;">        
                  <?php foreach ($array as $key => $value) { ?>
                    <div href="javascript:;" class="moment_thumb mr20 tooltip" data-moment="0" data-listing-num="1669">
                      <a href="<?php echo $value['url']; ?>">
                        <div class="moment-img-wrapper pos_rel moment_click" id="moment_wrapper_0">
                          <img class="" src="<?php echo $value['image']?>" id="moment_thumb_img_0">
                          <div class="img_overlay"></div>
                        </div>
                        <span class="tooltiptext ellipsis_text"><?php echo $value['title'] ?></span>
                      </a>
                    </div>
                  <?php } ?>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div> -->

    <div class="row">
      <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12">
        <div class="database_box"> 
          <div class="driver_wrap white_bg" id="recent_orders" data-order-nums="">
            <div style="position: relative;height: 5px;margin:0 -10px;overflow: hidden;">
                <div class="hr-grad-line searching_line search_line_animation"></div>
            </div>
            <div class="recent_order_box clearfix" style="position: relative;margin-bottom: 0">
              <div class="wifi-offline-text" style="position: absolute;top:0;left:0;display:none;align-items:center;background-color:#d93549;color:#fff;z-index:1;width:100%;height: 100%;padding-left: 15px;font-size: 20px;">
                  <p>Currently offline. Please check your internet conection.</p>
              </div>
              <div class="semi_bold_text mb20 white_text f_s_16 recent_order_horizontal_scroll" id="order_number"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <audio id="myAudio" src="https://urban-halal.s3-us-west-1.amazonaws.com/static_assets/landing_page/order-new.mp3"></audio>

    <div class="row">
      <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12">
        <div class="database_box" style="min-height: 300px;padding-top: 1px;"> 
          <div style="position: relative;">
            <!-- <div class="row">
              <div class="col-md-12 col-lg-12 col-sm-12"> -->
                <div id="chartdiv" style="width: 90%;height: 250px;margin-bottom:20px;margin-top: 40px;"></div>
             <!--  </div>
            </div> -->
          </div>
        </div>
      </div>
    </div>

    <div class="row">
      <div class="col-md-12 col-lg-12 col-sm-12 text-center mt15">
        <div class="database_box" style="min-height: 200px;"> 
        <!-- <div class="col-md-12 text-center mt15"> -->
          
            <div class="col-md-4 col-xs-4">
              <h1 class="bold_text mt10"><?php echo @$deliveredOrderCount;?></h1>
              <span>Delivered Orders</span>
            </div>
            <div class="col-md-4 col-xs-4">
              <h1 class="bold_text mt10"><?php echo @$cancelledOrderCount;?></h1>
              <span>Cancelled Orders</span>
            </div>
            <div class="col-md-4 col-xs-4">
              <h1 class="bold_text mt10"><?php echo "$" . (@$totalAmount ? formatPrice($totalAmount) : "0.00");?></h1>
              <span>Total Amount</span>
            </div>
          
        <!-- </div> -->
        
        <!-- <div class="col-md-12 text-center mt15"> -->
           
            <div class="col-md-4 col-xs-4">
              <h1 class="bold_text mt10"><?php echo "$" . (@$refundedAmount ? formatPrice($refundedAmount) : "0.00");?></h1>
              <span>Refund Amount</span>
            </div>
            <?php if($CURRENT_USER['isAdmin']) { ?>
            <div class="col-md-4 col-xs-4">
              <h1 class="bold_text mt10"><?php echo "$" . (@$totalTip ? formatPrice($totalTip) : "0.00");?></h1>
              <span>Total Tip Amount</span>
            </div>
            <div class="col-md-4 col-xs-4">
              <h1 class="bold_text mt10"><?php echo "$" . (@$avgCart ? formatPrice($avgCart) : "0.00");?></h1>
              <span>Avg. Cart</span>
            </div>
            <?php } ?>
          
        <!-- </div> -->
      </div>
      </div>
    </div>

    <?php if($CURRENT_USER['isAdmin']) {?>
      <div class="row">
        <div class="col-md-8">  
          <div class="form-group form-inline">
            <input name="menu" value="home" id="menu" type="hidden">
            <input type="text" value="<?php echo @$labelFromDate; ?>" name="fromDate" id="fromDate" class="form-control" placeholder="From Date" style="width: 100px;display: inline-block;" readonly/>   
            <input type="text" value="<?php echo @$labelToDate; ?>" name="toDate" id="toDate" class="form-control" placeholder="To Date" style="width: 100px;display: inline-block;" readonly/>  
            
            <div class="input-group">
              <input type="hidden" name="listingsNum" value="<?php echo isset($listingNumSelect) ? $listingNumSelect : '';  ?>">  
                <select name="listingsNum" id="table" class="form-control js-basic-multiple" style="display: inline-block;" <?php echo $CURRENT_USER['isAdmin'] ? '' : 'disabled' ?>>
                  <option value="">Select Listing</option>
                  <?php foreach($listings as $listing):
                    $address = json_encode($listing);
                  ?>
                    <option value="<?php echo htmlencode($listing['num']); ?>" data-listing-address='<?php echo htmlencode($address) ?>' <?php echo isset($listingNumSelect) && $listingNumSelect == $listing['num'] ? "selected" : ""  ?> ><?php echo htmlencode($listing['name']); ?></option>
                  <?php endforeach; ?>
                </select>
            </div>
            <input type="submit" name="filter" id="filter" value="Filter" class="btn btn-info" />  
          </div>
        </div>
        <div class="col-md-4">  
          <div class="form-group form-inline">          
            <select id="orderSort" name="orderSort" class="form-control pull-right" onchange="this.form.submit();">
                <option value="">Sort By</option>
                <option value="`order_status` ASC">Order Status Asc</option>
                <option value="`order_status` DESC">Order Status Desc</option>
                <option value="`createdDate` ASC">Order Date Asc</option>
                <option value="`createdDate` DESC">Order Date Desc</option>
            </select> 
          </div>
        </div>
      </div>
    <?php }else{ ?>
      <div class="row">
        <div class="col-md-8">  
          <!-- <div class="form-group form-inline text-center" style="margin-right: 150px;">
              <input name="menu" value="sales_dashboard" id="menu" type="hidden">
              <input type="hidden" name="fromDate"  value="<?php echo @$labelFromDate; ?>" class="form-control">
              <input type="hidden" name="toDate"  value="<?php echo @$labelToDate; ?>" class="form-control">
              <a href="#" type="button" onclick="calculateDate(-1)" style="color:rgb(217, 53, 73);"><i class="fa fa-long-arrow-left" aria-hidden="true"></i></a>
              <span><?php echo @$labelFromDate ." &#9866; ". @$labelToDate;?></span>
              <input type="hidden" name="changeDate" class="form-control" id="changeDate" value="-1">
              <a href="#" type="button" onclick="calculateDate(1)" style="color:rgb(217, 53, 73);"><i class="fa fa-long-arrow-right" aria-hidden="true"></i></a>
          </div> -->
          <div class="form-group form-inline">
            <input name="menu" value="sales_dashboard" id="menu" type="hidden">
            <input type="text" value="<?php echo @$labelFromDate; ?>" name="fromDate" id="fromDate" class="form-control" placeholder="From Date" style="width: 100px;display: inline-block;" readonly/>  
             
            <input type="text" value="<?php echo @$labelToDate; ?>" name="toDate" id="toDate" class="form-control" placeholder="To Date" style="width: 100px;display: inline-block;" readonly/>  

            <input type="submit" name="filter" id="filter" value="Filter" class="btn btn-info" />  
          </div>
        </div>
      </div>
    <?php } ?>
    
    <?php echo getPaginationHTML($metaData, 'top'); ?>
    
    <div class="row">
      <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12">
        <div class="database_box"> 
          <div class="horizontal-autoscroll" id="order_table">
            <table class="table table-hover table-striped" >
              <thead>
                <tr>
                  <th>Created Date</th>
                  <?php if($CURRENT_USER['isAdmin']) { ?>
                  <th>Listing</th>
                  <?php } ?>
                  <th>Order Number</th>
                  <th>Items</th>
                  <th>Order Total</th>
                  <th>Order Status</th>
                  <th>Action</th>
                </tr>
              </thead>
              <tbody>
                <?php foreach($orders as $order): ?>
                <?php
                  $totalItems = mysql_get_query("SELECT SUM(quantity) as count FROM urbanhal_order_items WHERE ordersNum = {$order['num']}");

                  $orderDetail = mysql_get("order_detail", null, "`ordersNum` = '".$order['num']."'", "`postmates_response_data`");

                  $responseData = !empty($orderDetail['postmates_response_data']) ? json_decode($orderDetail['postmates_response_data'],true) : "";

                  $originalDeliveryFee = 0;

                    if(isset($responseData['fee']) && !empty($responseData['fee'])){

                      $originalDeliveryFee = $responseData['fee'] / 100;
                    }

                  $orderTotal = $order['total'];
                  if(!$CURRENT_USER['isAdmin']) {
                    $orderTotal = calculateOrderTotal($order);
                  }

                  $listing = mysql_get("listings",$order['listingsNum'],null,'`timezone`,`name`,`zip`');

                  $utcTime = strtotime($order['createdDate']);

                  $localTime = date("Y-m-d H:i:s", $utcTime);

                  if(!$CURRENT_USER['isAdmin']) {

                  $localTime = utcTimeToLocalTime($utcTime,$listing['timezone'],true, 'Y-m-d H:i:s', 'Y-m-d H:i:s');

                  }

                ?>

                <tr class="cp" onclick="showOrderDetail(<?php echo $order['num'] ?>);">
                  <td><?php echo date("m-d-Y h:i:s A", strtotime($localTime)); ?></td>
                  <?php if($CURRENT_USER['isAdmin']) { 

                    if($order['order_status']=='delivered'){

                    $orderTotal = $order['total'];// - $originalDeliveryFee;

                  }


                  ?>
                  <td><?php echo $listing['name']." - ".$listing['zip']; ?></td>
                  <?php  } ?>
                  <td><?php echo $order['order_number']; ?></td>
                  <td>
                    <?php echo $totalItems['count']; ?></td>
                  <td><?php echo "$" . formatPrice($orderTotal); ?></td>
                  <?php  if($order['order_status']=='cancelled'){
        
                         $orderStatusColor = '#d93549';
        
                       }elseif($order['order_status']=='refunded'){

                         $orderStatusColor = '#f5b222';

                      }elseif($order['order_status']=='delivered'){

                         $orderStatusColor = '#5bbc2e';
                      }else{

                       $orderStatusColor ='#000000';
                      }
                   ?>
                  <td class="semi_bold_text" style="color:<?php echo $orderStatusColor; ?>"><?php echo strtoupper($order['order_status']); ?></td>
                  <td class="semi_bold_text" ><a href="?menu=orders&action=edit&num=<?php echo $order['num']; ?>" target="_blank" onclick="event.stopPropagation();">EDIT</a></td>
                </tr>
                
                <?php endforeach; ?>
                <?php if(count($orders) < 1): ?>
                  <tr>
                    <td colspan="5" class="text-center">No Reocrds Found</td>
                  </tr>
                <?php endif; ?>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
    
<!--      -->
    <div class="row">
      <div class="col-md-12 col-lg-12 col-sm-12">
        <div class="database_box" style="min-height: 420px;">
          <div style="padding: 10px 29px;font-size: 20px;font-weight: 600;">LISTING PAYOUTS</div>
          <div class="col-md-4 text-center">
            <h1 class="bold_text mt10"><?php echo $userOrder;?></h1>
            <span >Total Orders</span>
          </div>
          <div class="col-md-4 text-center mt15">
            <h1 class="bold_text mt10">$<?php echo $userPayout;?></h1>
            <span >Total Net Payout</span>
          </div>

          <div id="chartdiv1" style="width: 90%;height: 250px;margin-bottom:15px;"></div>

        </div>
      </div>
    </div>
    

    <div id="order-detail-panel" style="position: fixed;z-index: 1;width: 0px;height: 100vh;background: #f1f1f1;top: 0px;right: 10px;transition: width .5s ease-in-out;overflow: hidden;border: 1px solid #cccccc;">
        <div class="f_s_18 pull-left cp ml10" onclick="closeCurrentView()"><i class="fa fa-close"></i></div>
        <div id="dataLoader" style="position: absolute;left: 50%;top: 50%;z-index: 1;font-size: 1.5em;display: none;margin-top: -30px;">
          <i class="fa fa-spinner fa-spin fa-2x"></i>
        </div>
      <div id="order-detail" class="driver_wrap" style="margin-top: 20px;">
      </div>
    </div>

    <div class="row">
        <!-- <div class="col-md-6 col-lg-6 col-sm-12">
            <div class="database_box" style="">
                <div class="database_headding">
                    <h4 class="data_head">URBAN HALAL QUICK LAUNCH</h4>
                    <span class="data_headlast">PLATFORM STACK</span>
                </div>
                <div class="quick_launches_wrap text-center">
                    <div class="row">
                       <div class="col-md-3 col-sm-4 col-xs-6 quick_launch">
                            <p><a href="https://aws.amazon.com/console/" target="_blank">AWS Console</a></p>
                        </div>
                        <div class="col-md-3 col-sm-4 col-xs-6 quick_launch">
                            <p><a href="https://console.aws.amazon.com/workmail/v2/home?region=us-east-1#/"  target="_blank">AWS Email</a></p>
                        </div>
                        <div class="col-md-3 col-sm-4 col-xs-6 quick_launch">
                            <p><a href="https://s3.console.aws.amazon.com/s3/home?region=us-west-1#"  target="_blank">AWS S3</a></p>
                        </div>
                        <div class="col-md-3 col-sm-4 col-xs-6 quick_launch">
                            <p><a href="https://cloudeq.atlassian.net/jira/projects"  target="_blank">Jira CloudEQ</a></p>
                        </div>
                        <div class="col-md-3 col-sm-4 col-xs-6 quick_launch">
                            <p><a href="https://developers.google.com/"  target="_blank">GCloud</a></p>
                        </div>
                        <div class="col-md-3 col-sm-4 col-xs-6 quick_launch">
                            <p><a href="https://business.facebook.com/"  target="_blank">FB Business</a></p>
                        </div>
                        <div class="col-md-3 col-sm-4 col-xs-6 quick_launch">
                            <p><a href="https://www.doordash.com/drive"  target="_blank">Doordash</a></p>
                        </div>
                        <div class="col-md-3 col-sm-4 col-xs-6 quick_launch">
                            <p><a href="https://partner.postmates.com/dashboard/home"  target="_blank">Postmates partner</a></p>
                        </div>
                    </div>
                </div>             
            </div>
        </div> -->
        <!-- <div class="col-md-6 col-lg-6 col-sm-12 ">
            <div class="database_box time-zones-container">
                <div class="database_headding">
                    <h4 class="data_head">TIME ZONES</h4>
                    <span class="data_headlast">PLATFORM SYNC</span>
                </div>
                
                <div class="clocks-container row clocks active bounce">
                    <div class="col-md-4 col-sm-4 col-xs-6 clock-wrapper">
                        <article class="clock station js-hawaii">
                            <section class="hours-container">
                              <section class="hours"></section>
                            </section>
                            <section class="minutes-container">
                              <section class="minutes"></section>
                            </section>
                            <section class="seconds-container">
                              <section class="seconds"></section>
                            </section>
                            
                        </article>
                        <h5 class="clock-label">Honolulu</h5>
                        <div id="js-hawaii" class="digit-time"></div>
                    </div>
                    
                    <div class="col-md-4 col-sm-4 col-xs-6 clock-wrapper">
                        <article class="clock station js-alaska">
                            <section class="hours-container">
                              <section class="hours"></section>
                            </section>
                            <section class="minutes-container">
                              <section class="minutes"></section>
                            </section>
                            <section class="seconds-container">
                              <section class="seconds"></section>
                            </section>
                            
                        </article>
                        <h5 class="clock-label">Alaska</h5>
                        <div id="js-alaska" class="digit-time"></div>
                    </div>

                    <div class="col-md-4 col-sm-4 col-xs-6 clock-wrapper">
                        <article class="clock station js-pacific">
                            <section class="hours-container">
                              <section class="hours"></section>
                            </section>
                            <section class="minutes-container">
                              <section class="minutes"></section>
                            </section>
                            <section class="seconds-container">
                              <section class="seconds"></section>
                            </section>
                            
                        </article>
                        <h5 class="clock-label">Los Angeles</h5>
                        <div id="js-pacific" class="digit-time"></div>
                    </div>

                    <div class="col-md-4 col-sm-4 col-xs-6 clock-wrapper">
                        <article class="clock station js-central">
                            <section class="hours-container">
                              <section class="hours"></section>
                            </section>
                            <section class="minutes-container">
                              <section class="minutes"></section>
                            </section>
                            <section class="seconds-container">
                              <section class="seconds"></section>
                            </section>
                            
                        </article>
                        <h5 class="clock-label">Chicago</h5>
                        <div id="js-central" class="digit-time"></div>
                    </div>

                    <div class="col-md-4 col-sm-4 col-xs-6 clock-wrapper">
                        <article class="clock station js-eastern">
                            <section class="hours-container">
                              <section class="hours"></section>
                            </section>
                            <section class="minutes-container">
                              <section class="minutes"></section>
                            </section>
                            <section class="seconds-container">
                              <section class="seconds"></section>
                            </section>
                            
                        </article>
                        <h5 class="clock-label">New York</h5>
                        <div id="js-eastern" class="digit-time"></div>
                    </div>

                    <div class="col-md-4 col-sm-4 col-xs-6 clock-wrapper">
                        <article class="clock station js-mountain">
                            <section class="hours-container">
                              <section class="hours"></section>
                            </section>
                            <section class="minutes-container">
                              <section class="minutes"></section>
                            </section>
                            <section class="seconds-container">
                              <section class="seconds"></section>
                            </section>
                            
                        </article>
                        <h5 class="clock-label">Arizona</h5>
                        <div id="js-mountain" class="digit-time"></div>
                    </div>
                </div>     
            </div>
        </div> -->
    </div>
    <div class="row">
     
<!--         <div class="col-md-6 col-lg-6 col-sm-12">
            <div class="database_box" style=" padding: 10px 10px 10px 10px;">
                <div class="database_headding">
                    <h4 class="data_head text-center">PLATFORM HEALTH CHECK</h4>
                    <span class="data_headlast"><?php echo date("l, F d, Y", strtotime($stats['updatedDate'])); ?></span>
                </div>

                <div class="total_count">
                    <h1 class="text-center"><?php echo $stats['all_users']; ?></h1>
                </div>

                <div class="platform_users">
                    <span>
                        <img src="plugins/modifyHomepage/images/apple.svg">
                        <?php echo $stats['ios_users']; ?>
                    </span>
                    <span>
                        <img src="plugins/modifyHomepage/images/android.svg">
                        <?php echo $stats['android_users']; ?>
                    </span>
                </div>

                <div class="platform_stats">
                    <div class="row margin_none">
                        
                        <div class="col-xs-6 col-md-4 col-sm-6">
                            <div class="platform_box">
                                <div class="platform_statstxt">
                                    <div class="icon_holder">
                                        <img src="https://s3-us-west-1.amazonaws.com/urban-halal/static_assets/svgs/invites.svg">
                                    </div>
                                    <div class="stats_holder">
                                        <?php echo $stats['sms_invites']; ?>
                                        <br>
                                        <span>INVITES</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-xs-6 col-md-4 col-sm-6">
                            <div class="platform_box">
                                <div class="platform_statstxt">
                                    <div class="icon_holder">
                                        <img src="https://s3-us-west-1.amazonaws.com/urban-halal/static_assets/svgs/email-icon.svg">
                                    </div>
                                    <div class="stats_holder">
                                        <?php echo $stats['newsletter_subscribers']; ?>
                                        <br>
                                        <span>EMAILS</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-xs-6 col-md-4 col-sm-6">
                            <div class="platform_box">
                                <div class="platform_statstxt">
                                    <div class="icon_holder">
                                        <img src="https://s3-us-west-1.amazonaws.com/urban-halal/static_assets/svgs/share-icon.svg">
                                    </div>
                                    <div class="stats_holder">
                                        <?php echo $stats['shared_content']; ?>
                                        <br>
                                        <span>SHARES</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-xs-6 col-md-4 col-sm-6">
                            <div class="platform_box">
                                <div class="platform_statstxt">
                                    <div class="icon_holder">
                                        <img src="https://s3-us-west-1.amazonaws.com/urban-halal/static_assets/svgs/Moments.svg">
                                    </div>
                                    <div class="stats_holder">
                                        <?php echo $stats['photo_uploads']; ?>
                                        <br>
                                        <span>MOMENTS</span>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-xs-6 col-md-4 col-sm-6">
                            <div class="platform_box">
                                <div class="platform_statstxt">
                                    <div class="icon_holder">
                                        <img src="https://s3-us-west-1.amazonaws.com/urban-halal/static_assets/svgs/moment-love.svg">
                                    </div>
                                    <div class="stats_holder">
                                        <?php echo $stats['photo_likes']; ?>
                                        <br>
                                        <span>LIKES</span>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-xs-6 col-md-4 col-sm-6">
                            <div class="platform_box">
                                <div class="platform_statstxt">
                                    <div class="icon_holder">
                                        <img src="https://s3-us-west-1.amazonaws.com/urban-halal/static_assets/svgs/certs.svg">
                                    </div>
                                    <div class="stats_holder">
                                        <?php echo $stats['certificate_uploads']; ?>
                                        <br>
                                        <span>CERTS</span>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-xs-6 col-md-4 col-sm-6">
                            <div class="platform_box">
                                <div class="platform_statstxt">
                                    <div class="icon_holder">
                                        <img src="https://s3-us-west-1.amazonaws.com/urban-halal/static_assets/svgs/tips.svg">
                                    </div>
                                    <div class="stats_holder">
                                        <?php echo $stats['tips']; ?>
                                        <br>
                                        <span>TIPS</span>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-xs-6 col-md-4 col-sm-6">
                            <div class="platform_box">
                                <div class="platform_statstxt">
                                    <div class="icon_holder">
                                        <img src="https://s3-us-west-1.amazonaws.com/urban-halal/static_assets/svgs/rank.svg">
                                    </div>
                                    <div class="stats_holder">
                                        <?php echo $stats['rated']; ?>
                                        <br>
                                        <span>RATINGS</span>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-xs-6 col-md-4 col-sm-6">
                            <div class="platform_box">
                                <div class="platform_statstxt">
                                    <div class="icon_holder">
                                        <img src="https://s3-us-west-1.amazonaws.com/urban-halal/static_assets/svgs/checkin.svg">
                                    </div>
                                    <div class="stats_holder">
                                        <?php echo $stats['check_ins']; ?>
                                        <br>
                                        <span>CHECK-INS</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                    </div> 
                </div>
                                      
            </div>
        </div> -->
        
        
<!--         <div class="col-md-6 col-lg-6 col-sm-12">
            <div class="database_box" style="">
                <div class="database_headding">
                    <h4 class="data_head">HALAL FOODIE MAP</h4>
                    <span class="data_headlast">USERS ACROSS THE US</span>
                </div>             
               
                <div class="row">
                     <div class="col-sm-12">
                    <div id="us_map">
                    </div>
                </div> 
                </div>
                                 

            </div>        
                                
        </div>  -->

    </div>

    <div class="row">
        <!-- <div class="col-md-6 col-lg-6 col-sm-6">
            <div class="database_box" style=" padding: 10px 10px 10px 10px;">
                <div class="database_headding">
                    <h4 class="data_head text-center">TRENDING TAGS</h4>
                    <span class="data_headlast">CUISINES</span>
                </div>

                <?php //include "tags.php"; ?>

            </div>
        </div> -->
        <!-- <div class="col-md-6 col-lg-6 col-sm-6">
            <div class="database_box" style=" padding: 10px 10px 10px 10px;">
                <div class="database_headding">
                    <h4 class="data_head text-center">ACTIVE DAILY USERS</h4>
                    <span class="data_headlast">CURRENT VS TOTAL</span>
                </div>

                <?php include "leaderboard.php"; ?>

            </div>
        </div> -->
    </div>

<!--     <div class="row database_box"> -->
            
<!--         <div class="col-md-4 col-lg-4">
            <div class="database_headding">
                <h4 class="data_head text-center">BRAND NEW USER</h4>
                <span class="data_headlast">RECENT</span>
            </div>
    
            <div class="brand_user_wrap text-center">
                <div class="userimg">
                    <img src="<?php echo $recentUser['facebook_picture']; ?>" alt="">
                </div>
                <div class="username"><?php echo $recentUser['username']; ?></div>
                <div class="points"><?php echo $recentUser['points']; ?> POINTS</div>

                <div class="user_stats">
                    <div class="user_stats_left">
                        <?php echo $userInvites; ?>
                        <span>INVITES</span>
                    </div>
                    <div class="user_stats_right">
                        <?php echo $recentUser['total_shares'] ?:0; ?>
                        <span>SHARES</span>
                    </div>
                </div>
            </div>
           
        </div> -->
<!--         <div class="col-md-8 col-lg-8">
            <div class="database_headding">
                <h4 class="data_head text-center">#HELLAHALAL EXPERIENCE</h4>
                <span class="data_headlast">USER ACTIVITY</span>
            </div>

            <div class="collapse colapse_cus in" id="col8">
                <ul class="nav nav-tabs border-1" role="tablist">
                    <li role="checkins" class="active">
                        <a href="#checkins" aria-controls="checkins" role="tab" data-toggle="tab">
                            <span class="gray">Check-ins</span>
                            <span class="red">Check-ins</span>
                        </a>
                    </li>
                    <li role="tips">
                        <a href="#tips" aria-controls="tips" role="tab" data-toggle="tab">
                            <span class="gray">Tips</span>
                            <span class="red">Tips</span>
                        </a>
                    </li>
                    <li role="moments">
                        <a href="#moments" aria-controls="moments" role="tab" data-toggle="tab">
                            <span class="gray">Moments</span>
                            <span class="red">Moments</span>
                        </a>
                    </li>
                    <li role="ratings">
                        <a href="#ratings" aria-controls="ratings" role="tab" data-toggle="tab">
                            <span class="gray">Ratings</span>
                            <span class="red">Ratings</span>
                        </a>
                    </li>
                </ul>

                <div class="line_graph_box">
                    <div class="tab-content tab-content1">
                        <div role="checkins" class="tab-pane active" id="checkins" data-limit="10" data-offset="0">
                            <?php include('checkinGraph.php'); ?>
                        </div>
                        <div role="tips" class="tab-pane" id="tips" data-limit="10" data-offset="0">
                            <?php include('tipsGraph.php'); ?>
                        </div>
                        <div role="moments" class="tab-pane" id="moments" data-limit="10" data-offset="0">
                            <?php include('momentsGraph.php'); ?>
                        </div>
                        <div role="ratings" class="tab-pane" id="ratings" data-limit="10" data-offset="0">
                            <?php include('ratingsGraph.php'); ?>
                        </div>
                    </div>
                </div>
            </div>
           
        </div> -->
            
       
<!--     </div> -->

    <!-- <div class="row"> -->
        <!-- <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12">
            <div class="database_box">
                <div class="database_headding">
                    <h4 class="data_head text-center">PLATFORM COMMUNICATIONS</h4>
                    <span class="data_headlast">WEEKLY NEWSLETTER</span>
                </div>
                <div class="newsletter_stats">

                    <div class="total_count">
                        <h1 class="text-center">5463</h1>   
                    </div>
                        
                    <div class="top_brids">
                        <span class="week_red">This Week in San Francisco</span>
                    </div>
                
                    <div class="ave_box_outer">
                        <div class="row">
                            <div class="col-xs-6 col-sm-4">
                                <div class="ave_box">
                                    <h3><?php echo $openedCount; ?></h3>
                                    <p>OPENS</p>
                                </div>
                            </div>
                    
                            <div class="col-xs-6 col-sm-4">
                                <div class="ave_box">
                                    <h3><?php echo $clickedCount; ?></h3>
                                    <p>CLICKS</p>
                                </div>
                            </div>
                    
                             <div class="col-xs-6 col-sm-3">
                                <div class="ave_box">
                                    <h3>8</h3>
                                    <p>BOUNCE</p>
                                </div>
                            </div>
                    
                            <div class="col-xs-6 col-sm-4   ">
                                <div class="ave_box">
                                    <h3><?php echo $unsubCount; ?></h3>
                                    <p>UNSUBS</p>
                                </div>
                            </div>
                    
                        </div>
                    </div>
               
                    <div class="nl_stats_progress">
                        <div class="top_prog row">
                            <div class="col-xs-6">OPENS</div>
                            <div class="col-xs-6 text-right"><span>41.6%</span></div>
                        </div>
                        <div class="progress">
                            <div class="progress-bar" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" style="width:70%">
                                <span class="sr-only">70% Complete</span>
                            </div>
                        </div>
                    
                        <div class="bott_prog row">
                            <div class="col-xs-6 list_left">AVERAGE <span>37.4%</span></div>
                            <div class="col-xs-6 text-right list_right">INDUSTRY AVERAGE<span>37.4%</span></div>
                        </div>
                    
                    
                        <div class="top_prog row">
                            <div class="col-xs-6">CLICKS</div>
                            <div class="col-xs-6 text-right"><span>41.6%</span></div>
                        </div>
                        <div class="progress">
                            <div class="progress-bar" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" style="width:70%">
                                <span class="sr-only">70% Complete</span>
                            </div>
                        </div>
                    
                        <div class="bott_prog row">
                            <div class="col-xs-6 list_left">AVERAGE <span>37.4%</span></div>
                            <div class="col-xs-6 text-right list_right">INDUSTRY AVERAGE<span>37.4%</span></div>
                        </div>   
                    </div>
                
                </div>
            </div>
        </div> -->

        <!-- <div class="col-md-5 col-lg-4 col-sm-6 col-xs-12">
            <div class="database_box">
                <div class="database_headding">
                    <h4 class="data_head text-center">#HELLAHALAL MOMENTS</h4>
                     <span class="data_headlast">USER ACTIVITY</span>
                </div>
                <div class="feed_box_wrapper">
                    <ul class="nav nav-tabs border-1" role="tablist">
                        <li role="momentsTab" class="active">
                            <a href="#momentsTab" aria-controls="momentsTab" role="tab" data-toggle="tab">
                                 <img src="plugins/modifyHomepage/images/charts.svg" class="gray">
                                <img src="plugins/modifyHomepage/images/charts-a.svg" class="red">
                                <span class="gray">MOMENTS</span>
                                <span class="red">MOMENTS</span>
                            </a>
                        </li>
                        <li role="feedActionsTab">
                            <a href="#feedActionsTab" aria-controls="feedActionsTab" role="tab" data-toggle="tab">
                                 <img src="plugins/modifyHomepage/images/apple3-01.svg" class="gray ff">
                                <img src="plugins/modifyHomepage/images/apple3-01a.svg" class="red ff"> 
                                <span class="gray">ACTIONS</span>
                                <span class="red">ACTIONS</span>
                            </a>
                        </li>
                    </ul>

                    <div class="line_graph_box">
                        <div class="tab-content tab-content1">
                            <div role="momentsTab" class="tab-pane active" id="momentsTab">
                                <div class="moments_box" style="overflow: auto;height:400px;">
                                    <div id="momentsLoader"><i class="fa fa-spin fa-spinner fa-2x"></i></div>
                                    <div class="moments_wrapper" data-limit="10" data-offset="0">
                                        <?php include('moments.php'); ?>
                                    </div>
                                </div>
                            </div>
                            <div role="feedActionsTab" class="tab-pane" id="feedActionsTab">
                                <div class="feed_box" style="height: 400px;overflow:auto;">
                                    <div id="feedLoader"><i class="fa fa-spin fa-spinner fa-2x"></i></div>
                                    <div id="feed_wrapper" data-limit="10" data-offset="0">
                                        <?php include('feed.php'); ?>
                                    </div>
                                </div>
                            </div>  
                        </div>
                    </div> 
                </div>
            </div>
        </div> -->

    <!-- </div> -->
            
    <script src="plugins/modifyHomepage/js/mapdata.js"></script>
    <script src="plugins/modifyHomepage/js/usmap.js"></script>
    <script src="plugins/modifyHomepage/js/custom.js"></script>
    <script type="text/javascript">
    // Themes begin
    am4core.useTheme(am4themes_animated);
    // Themes end

    // Create chart instance
    let orderChart = am4core.create("chartdiv", am4charts.XYChart);

    // Add data
    orderChart.data = <?php echo json_encode($chartData,JSON_PRETTY_PRINT); ?>;
    // Create axes

    var categoryAxis = orderChart.xAxes.push(new am4charts.CategoryAxis());
    categoryAxis.dataFields.category = "date";
    categoryAxis.renderer.grid.template.location = 0;
    categoryAxis.renderer.minGridDistance = 30;

    categoryAxis.renderer.labels.template.adapter.add("dy", function(dy, target) {
      if (target.dataItem && target.dataItem.index & 2 == 2) {
        return dy + 25;
      }
      return dy;
    });

    var valueAxis = orderChart.yAxes.push(new am4charts.ValueAxis());
      valueAxis.maxPrecision = 0;
    // Create series
    var series = orderChart.series.push(new am4charts.ColumnSeries());
    series.dataFields.valueY = "count";
    series.dataFields.categoryX = "date";
    series.name = "Orders";
    series.columns.template.tooltipText = "{categoryX}: [bold]{valueY}[/]";
    series.columns.template.fillOpacity = 1;
    series.columns.template.fill = am4core.color("#d93549"); // red
    series.stroke = am4core.color("#d93549"); // red

    var columnTemplate = series.columns.template;
    columnTemplate.strokeWidth = 2;
    columnTemplate.strokeOpacity = 1;

    //payout chart
    let payData = <?php echo json_encode($chartData1,JSON_PRETTY_PRINT); ?>;
    //if(payData.length){
      // Themes begin
      am4core.useTheme(am4themes_animated);
      // Themes end

      // Create chart instance
      let payoutChart = am4core.create("chartdiv1", am4charts.XYChart);

      // Add data
      payoutChart.data = payData
      // Create axes

      var categoryAxis = payoutChart.xAxes.push(new am4charts.CategoryAxis());
      categoryAxis.dataFields.category = "date";
      categoryAxis.renderer.grid.template.location = 0;
      categoryAxis.renderer.minGridDistance = 30;

      categoryAxis.renderer.labels.template.adapter.add("dy", function(dy, target) {
        if (target.dataItem && target.dataItem.index & 2 == 2) {
          return dy + 25;
        }
        return dy;
      });

      var valueAxis = payoutChart.yAxes.push(new am4charts.ValueAxis());
        valueAxis.maxPrecision = 0;
      // Create series
      var series = payoutChart.series.push(new am4charts.ColumnSeries());
      series.dataFields.valueY = "count";
      series.dataFields.categoryX = "date";
      series.name = "Orders";
      series.columns.template.tooltipText = "{categoryX}: [bold]{valueY}[/]";
      series.columns.template.fillOpacity = .8;
      series.columns.template.fill = am4core.color("#d93549"); // red
      series.stroke = am4core.color("#d93549"); // red

      var columnTemplate = series.columns.template;
      columnTemplate.strokeWidth = 2;
      columnTemplate.strokeOpacity = 1;

    function showOrderDetail(ordersNum){
      document.getElementById("order-detail-panel").style.width = "400px";
      $("#order-detail").html("").hide();
      $("#dataLoader").show();
      setTimeout(function(){
        getOrderDetail(ordersNum)
      }, 1000);
    }

  
    function getOrderDetail(ordersNum){  
      $.ajax({
        url: '?menu=sales_dashboard',
        data: {'ordersNum':ordersNum, 'action': 'show'},
        type: 'GET',
        dataType: 'html',
        success: function(res){
          $("#dataLoader").hide();
          $("#order-detail").html(res).show();
        },
        error:  function(msg){  },

      });
    }
      
    function closeCurrentView(){
      $("#order-detail").html("").hide();
      document.getElementById("order-detail-panel").style.width = "0px";
    }

    $(document).ready(function(){
    
      $(".js-basic-multiple").select2({
        placeholder: 'Select Listing',
        allowClear: true,
        sorter: function(results) {
              var query = $('.select2-search__field').val().toLowerCase();
            return results.sort(function(a, b) {
              return a.text.toLowerCase().indexOf(query) -
                b.text.toLowerCase().indexOf(query);
            });
          }
      });

      $("#fromDate").datepicker({  // this is from: lib/menus/default/edit_functions.php
        showOn: 'button',
      //yearRange: '<?php //echo($yearRangeStart . ':' . $yearRangeEnd); ?>',
      //changeYear: true,
        buttonImage: '<?php echo CMS_ASSETS_URL ?>/3rdParty/jqueryUI/calendar.gif',
        buttonImageOnly: true,
        dateFormat: 'mm-dd-yy',
        onClose: function(date) {
          var dateElements = date.split('-', 3);
        if (dateElements.length != 3) { dateElements = ['', '', '']; }
          
          var year  = dateElements[0];
          var month = dateElements[1].replace(/^[0]+/g, '');
          var day   = dateElements[2].replace(/^[0]+/g, '');
        }
      });

      $("#toDate").datepicker({  // this is from: lib/menus/default/edit_functions.php
          showOn: 'button',
        //yearRange: '<?php //echo($yearRangeStart . ':' . $yearRangeEnd); ?>',
        //changeYear: true,
          buttonImage: '<?php echo CMS_ASSETS_URL ?>/3rdParty/jqueryUI/calendar.gif',
          buttonImageOnly: true,
          dateFormat: 'mm-dd-yy',
          onClose: function(date) {
            var dateElements = date.split('-', 3);
          if (dateElements.length != 3) { dateElements = ['', '', '']; }
            
            var year  = dateElements[0];
            var month = dateElements[1].replace(/^[0]+/g, '');
            var day   = dateElements[2].replace(/^[0]+/g, '');
          }
      });
    });
    </script>  
    <script type="text/javascript">
    
    initLandingScreen();


    function initLandingScreen() {  
      /*if(showFirstOrderScreen()) {
        document.getElementById("first-order-screen").style.display = "block";
        setTimeout(function(){
          document.getElementById("order-screen-loader").style.display = "none";
          document.getElementById("show-recent-orders-text").style.display = "block";
          document.getElementById("show-recent-orders").style.pointerEvents = "auto";
        }, 1000);
      }else{*/
        loadRecentOrderScreen();
      /*}*/
    }

    function showFirstOrderScreen() {
      const itemStr = localStorage.getItem("show_landing");

      if (!itemStr) {
        return true;
      }

      const item = JSON.parse(itemStr);
      const now = new Date();

      if (now.getTime() > item.expiry) {
        localStorage.removeItem("show_landing");
        return true
      }

      return false;
    }

    function loadRecentOrderScreen() {
      const now = new Date();
            const item = {
        value: true,
        expiry: now.setHours(23,59,59,0),
      }
      localStorage.setItem("show_landing", JSON.stringify(item));
      localStorage.removeItem("activeOrder");

/*      document.getElementById("first-order-screen").style.display = 'none';
      document.getElementById("no-order-content").style.display = "block";
      document.getElementById("recent_orders").style.display = "block";*/

      getRecentOrders();
    }

    function getRecentOrders(page_reloaded = true) {
      $(".searching_line").removeClass("search_line_animation");

      let recentOrdersElm = document.getElementById("recent_orders");
      let playAudio = false;

      // send this nums to compare if new order comes in the response
      let nums = recentOrdersElm.getAttribute("data-order-nums");

      $.ajax({

        url: '?menu=see_orders',
        data: {'action':'recent_order', 'nums': nums, 'page_reloaded': page_reloaded},
        type: 'GET',
        dataType: 'json',
        success: function(res){
        
          var recentOrders = res;
          var attachedOrders = recentOrdersElm.getAttribute("data-order-nums").split(",");
          var recent = '';
          var orderNums = [];
          for(var i = 0; i < recentOrders.length; i++){

            // set the flag to true if the current loop num is not in attachedOrders  and new_order is true  
            if(!(attachedOrders.includes(recentOrders[i]['num'])) && recentOrders[i]['new_order']) {
              playAudio = true;
            }
            let newOrder = recentOrders[i]['new_order'] ? "new_order" : "";
              recent +='<a id="recent_order_num_' + recentOrders[i]['num'] + '" href="?menu=see_orders" target="_blank" class="recent_order_num '+ newOrder + '"  data-num="' + recentOrders[i]['num'] + '" onclick=""><ul><li class="recent_order_status">Order #' + recentOrders[i]['order_num'] + '</li><li class="f_s_30 bold_text" style="margin-top: 6px;line-height:1">' + recentOrders[i]['item_count'] + '</li><li style="opacity: 0.5" class="f_s_12">' + ((recentOrders[i]['item_count']) > 1 ? 'ITEMS':'ITEM') + '</li></ul></a>'; 
                  orderNums.push(recentOrders[i]['num']);
            }

            if(recentOrders.length<1){
              // if order view is opened don't show "no order image"
              let orderNum = localStorage.getItem("activeOrder");
          if(orderNum == undefined) {
                document.getElementById("no-orders").classList.remove("hide-elm");
              }
              $("#order_number").html("");

            }else{

              recentOrdersElm.setAttribute("data-order-nums", orderNums.join(","));

              $("#order_number").html(recent);

              // set active recent order
              let orderNum = localStorage.getItem("activeOrder");
              $("#recent_order_num_"+orderNum).addClass("recent_order_active");
              
              // play audio if new order in recent orders
              if(playAudio) {
                document.getElementById('myAudio').play();
              }

              document.getElementById("no-orders").classList.add("hide-elm");
            }

          $(".searching_line").addClass("search_line_animation");

        },
        error:  function(msg){ 
          $(".searching_line").addClass("search_line_animation");
        },
        complete: function() {
          setTimeout(function(){

              getRecentOrders(false);

          }, 10000);
        }

      });
      
      reloadOrderDetail();
    }

    function reloadOrderDetail() {
      let orderNum = localStorage.getItem("activeOrder");
      let orderStatus = $("#order-detail-inner").data("order-status");
      
      // prevent order detail view from updating if order status is received or
      // if order help modal is opened
      // this is to avoid the scenario when user is setting order ready time but at same time
      // order view get updated
      if(orderNum != undefined && orderStatus != 'received' && isOrderHelpHidden()) {
        getOrderDetail(orderNum);
      }
    }
    </script>
  <?php
}

// DON'T UPDATE ANYTHING BELOW THIS LINE

addFilter('admin_postlogin', 'modifyHomepage_redirect');
addFilter('home_title',      '_modifyHomepage_title',   null, 1);
addFilter('home_content',    '_modifyHomepage_content');

function modifyHomepage_redirect() {
    global $CURRENT_USER;

    if(!$CURRENT_USER['isAdmin']){
        $GLOBALS['MODIFY_HOMEPAGE_REDIRECT_QUERY'] = '?menu=see_orders'; // query string to use instead of home page
    }
    
    if (!@$GLOBALS['MODIFY_HOMEPAGE_REDIRECT_QUERY']) { return; }
    $menu = @$_REQUEST['menu'];
    if ($menu == 'home' || !$menu) {
        redirectBrowserToURL($GLOBALS['MODIFY_HOMEPAGE_REDIRECT_QUERY']);
        exit;
    }
}

function _modifyHomepage_title($home_title) {
  ob_start();
  modifyHomepage_title();
  return ob_get_clean();
}  

function _modifyHomepage_content($content) {
  ob_start();
  modifyHomepage_content();
  return ob_get_clean();
}  
?>