<?php
$cs = Yii::app()->getClientScript();
$cs->registerScript("deleteUsers",  "function deleteUsers(id){
    var r = confirm('Are you sure to delete this?');
        if(r==true)
        {
            jQuery.ajax({
              'type'  : 'post',
              'data'  : 'id=' + id,
              'url'  : $('#liveSite').val()+'index.php?r=users/DeleteUsers',
              'cache': false,
              'success':function(data){
                if(data=='fail'){
                    t8.error('Error while Delete');
                }else {
                    location.href=$('#liveSite').val()+'index.php?r=users/index';
       
                    t8.success('Users deleted SuccessFully');
                }
               }
            });
        }

   
};", CClientScript::POS_HEAD);
$cs = Yii::app()->getClientScript();
$baseUrl = Yii::app()->baseUrl;

$cs->registerScript("loadUsers", '
        $(document).ready(function() {

        var table_id ="#tbl_user_details";
        var table = $(table_id).DataTable({
            scrollY         : "645px",
            //scrollX         : "true",
           // scrollCollapse  : true,
            pageLength      : 50,
			processing: true,
            ajax: {
                url: "' . Yii::app()->createUrl('users/GetSalesList') . '",
                type: "POST",
                cache : false,
            },
            serverSide:     true,
            fixedColumns:   true,
			processing: true,
            fixedHeader: {
                headerOffset: $("header.main").outerHeight()
            }
        } );
        $(".dataTables_scrollFoot").hide();
    });', CClientScript::POS_HEAD);
    ?>
    <section class="panel" style="background-color:#F6F3EE;">
        <header class="panel-heading clearfix panel-theame">
            <i class="fa fa-users"></i> Users  
<!--            <div class="pull-right">        
           
                <?php  if (isset(Yii::app()->user->havePermissionOn['admin_users_add']) ||  Yii::app()->user->authorised_user == 1) {?>
                
                <button class="btn btn-sm btn-theme" onclick="loadPopupModal('users/create','Add New User','lg')"><i class="fa fa-plus"></i> ADD</button>
          
                <?php } ?></div>-->
        </header>
        <div class="panel-body">
            <div class="custom-data-table">
                <table class="table table-hover table-bordered personal-task" id="tbl_user_details" style="font-size:13px;">
                    <thead>
                        <tr>
                            <th>SI No</th>
                            <th>User Name</th>
                            <th>Name</th>
                            <th>Designation</th>
                            <th>User Groups</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                             <th>SI No</th>
                            <th>User Name</th>
                            <th>Name</th>
                            <th>Designation</th>
                            <th>User Groups</th>
                            <th>Actions</th>
                            
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </section>
    <div>
    
    <?php
    
    
    
    function calculateWeekDate(){

        $noOfDaysInMonth = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
        $returnData      = array();
        for($day = 1; $day <= $noOfDaysInMonth; $day=$day+7) {
        $weekStartDate = date("Y-m-d", mktime(date("H"), date("i"), date("s"), date("m"), $day, date("Y")));
        $returnData[] = weekRange($weekStartDate);
        }
        return $returnData;
    }

    function weekRange($date) {
        $ts = strtotime($date);
        $start = (date('w', $ts) == 0) ? $ts : strtotime('last monday', $ts);
        $startWeekDate = date('Y-m-d', $start);
        $endWeekDate = date('Y-m-d', strtotime('next sunday', $start));
        return array(date('Y-m-d', $start), date('Y-m-d', strtotime('next sunday', $start)));
    }
    $weekly_date_Arr = calculateWeekDate();
    
    foreach($weekly_date_Arr as $week => $value){
        foreach( $value as $date => $value2){
            //echo "$week $date => $value2\n<br />\n";
        }
    }
    //echo "<pre>";
    //print_r($weekly_date_Arr);
    
    
    ?>
    </div>
