<?php include_once("class/class.MySQL.php");
$db	=new MySQL();
$cur_dat=date('Y-m-d');
$userid=$_POST['userid'];
if($userid==1)
{
$query="select * from project_activity_done where `daily_dat` LIKE  '%$cur_dat%' order by id asc";
}else{
$query="select * from project_activity_done where `daily_dat` LIKE  '%$cur_dat%' and emp_id='$userid' order by id asc";
}
$res    = mysql_query($query);
 $count  = mysql_num_rows($res);
$page = (int) (!isset($_REQUEST['pageId']) ? 1 :$_REQUEST['pageId']);
$page = ($page == 0 ? 1 : $page);
$recordsPerPage = 10;
$start = ($page-1) * $recordsPerPage;
$adjacents = "2";
    
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($count/$recordsPerPage);
$lpm1 = $lastpage - 1;   
$pagination = "";
if($lastpage > 1)
    {   
        $pagination .= "<div class='pagination'>";
        if ($page > 1)
            $pagination.= "<a href=\"#Page=".($prev)."\" onClick='changePagination(".($prev).");'>&laquo; Previous&nbsp;&nbsp;</a>";
        else
            $pagination.= "<span class='disabled'>&laquo; Previous&nbsp;&nbsp;</span>";   
        if ($lastpage < 7 + ($adjacents * 2))
        {   
            for ($counter = 1; $counter <= $lastpage; $counter++)
            {
                if ($counter == $page)
                    $pagination.= "<span class='current'>$counter</span>";
                else
                    $pagination.= "<a href=\"#Page=".($counter)."\" onClick='changePagination(".($counter).");'>$counter</a>";     
                         
            }
        }
        elseif($lastpage > 5 + ($adjacents * 2))
        {
            if($page < 1 + ($adjacents * 2))
            {
                for($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
                {
                    if($counter == $page)
                        $pagination.= "<span class='current'>$counter</span>";
                    else
                        $pagination.= "<a href=\"#Page=".($counter)."\" onClick='changePagination(".($counter).");'>$counter</a>";     
                }
                $pagination.= "...";
                $pagination.= "<a href=\"#Page=".($lpm1)."\" onClick='changePagination(".($lpm1).");'>$lpm1</a>";
                $pagination.= "<a href=\"#Page=".($lastpage)."\" onClick='changePagination(".($lastpage).");'>$lastpage</a>";   
           
           }
           elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
           {
               $pagination.= "<a href=\"#Page=\"1\"\" onClick='changePagination(1);'>1</a>";
               $pagination.= "<a href=\"#Page=\"2\"\" onClick='changePagination(2);'>2</a>";
               $pagination.= "...";
               for($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
               {
                   if($counter == $page)
                       $pagination.= "<span class='current'>$counter</span>";
                   else
                       $pagination.= "<a href=\"#Page=".($counter)."\" onClick='changePagination(".($counter).");'>$counter</a>";     
               }
               $pagination.= "..";
               $pagination.= "<a href=\"#Page=".($lpm1)."\" onClick='changePagination(".($lpm1).");'>$lpm1</a>";
               $pagination.= "<a href=\"#Page=".($lastpage)."\" onClick='changePagination(".($lastpage).");'>$lastpage</a>";   
           }
           else
           {
               $pagination.= "<a href=\"#Page=\"1\"\" onClick='changePagination(1);'>1</a>";
               $pagination.= "<a href=\"#Page=\"2\"\" onClick='changePagination(2);'>2</a>";
               $pagination.= "..";
               for($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
               {
                   if($counter == $page)
                        $pagination.= "<span class='current'>$counter</span>";
                   else
                        $pagination.= "<a href=\"#Page=".($counter)."\" onClick='changePagination(".($counter).");'>$counter</a>";     
               }
           }
        }
        if($page < $counter - 1)
            $pagination.= "<a href=\"#Page=".($next)."\" onClick='changePagination(".($next).");'>Next &raquo;</a>";
        else
            $pagination.= "<span class='disabled'>Next &raquo;</span>";
        
        $pagination.= "</div>";       
    }
    
if(isset($_POST['pageId']) && !empty($_POST['pageId']))
{
    $id=$_POST['pageId'];
}
else
{
    $id='0';
}
$cur_dat=date('Y-m-d');
$userid=$_POST['userid'];
if($userid==1)
{
 $query="select * from project_activity_done where  `daily_dat` LIKE  '%$cur_dat%' order by id desc
limit ".mysql_real_escape_string($start).",$recordsPerPage";
}
else
{
 $query="select * from project_activity_done where  `daily_dat` LIKE  '%$cur_dat%' and emp_id='$userid' order by id desc
limit ".mysql_real_escape_string($start).",$recordsPerPage";
}
//echo $query;
$res    =   mysql_query($query);
$count  =   mysql_num_rows($res);
$HTML='';
function limit_words($string, $word_limit)
{
$words = explode(" ",$string);
return implode(" ",array_splice($words,0,$word_limit));
}

if($count > 0)
{
    while($row=mysql_fetch_array($res))
    {
	 
	 
	 $resultdsg = mysql_fetch_array(mysql_query("SELECT * FROM employee where e_id='$row[emp_id]' "));


$resultproj = mysql_fetch_array(mysql_query("SELECT * FROM project_table where id='$row[project_id]' "));

$resultproj_stg = mysql_fetch_array(mysql_query("SELECT * FROM project_stage where id='$row[stages_ids]' "));
 if($row['status_proj']==1){$stat='Done';}else{$stat='Not Done';}
	 
	 
        $post=$row['id'];
        $link=$row['id'];
        $HTML.='<div class="box_one_activityplan">';
        $HTML.='<div class="project_id_heading_4_activityreport">'.date("d-m-Y",strtotime($row['daily_dat'])).'</div>';
	    $HTML.='<div class="project_id_heading_4_activityreport">'.$row['week_id'].'</div>';
	    $HTML.='<div class="project_id_heading_4_activityreport">'.$resultproj['proj_name'].'</div>';
		$HTML.='<div class="project_id_heading_4_activityreport">'.$resultproj_stg['stage_id'].'</div>';
		$HTML.='<div class="project_id_heading_4_activityreport example"><a href="#" data-toggle="tooltip" title="'.$row['activities'].'">'.substr($row['activities'], 0, 10).'</a></div>';
		$HTML.='<div class="project_id_heading_4_activityreport">'. $row['hourss'].'</div>';
		$HTML.='<div class="project_id_heading_4_activityreport">'. $resultdsg['e_fname'].'</div>';
		$HTML.='<div class="project_id_heading_4_activityreport">'. $stat.'</div>';
		?>
		
		
	<?php 
	
   $HTML.='</div>'; }
	 
	
}
else
{
    $HTML='No Data Found';
}
echo $HTML;
echo $pagination;
?>