<?php include_once("class/class.MySQL.php");
$db	=new MySQL();
$userid=$_POST['userid'];

$wek_ss=$_POST['sel_wek'];
$wek_from=$_POST['wek_from'];
$wek_to=$_POST['wek_to'];
if($wek_ss)
{
   if($userid!=1)
	 {
 $query="select * from project_activity_done where week_no='$wek_ss' and emp_id='$userid' group by project_id  order by id asc";
     }
	 else
	 {
	 $query="select * from project_activity_done where week_no='$wek_ss' group by project_id  order by id asc";
	 }
}else{

  if($userid!=1)
	 {
$query="select * from project_activity_done where  emp_id='$userid' group by project_id  order by id asc";
     }
	 else
	 {
 $query="select * from project_activity_done group by project_id 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';
}

$userid=$_POST['userid'];
$wek_ss=$_POST['sel_wek'];
$wek_from=$_POST['wek_from'];
$wek_to=$_POST['wek_to'];
if($wek_ss)
{
  if($userid!=1)
  {
  
  $query="select * from project_activity_done where week_id='$wek_ss' and emp_id='$userid'  group by project_id order by id desc
limit ".mysql_real_escape_string($start).",$recordsPerPage";
  }
  else
  {
    $query="select * from project_activity_done where week_id='$wek_ss'  group by project_id order by id desc
limit ".mysql_real_escape_string($start).",$recordsPerPage";
  }
  
  
}else
{
       if($userid!=1)
       {
 $query="select * from project_activity_done where  emp_id='$userid' group by project_id  order by id desc
limit ".mysql_real_escape_string($start).",$recordsPerPage";
      }
	  else
	  {
	  $query="select * from project_activity_done group by project_id  order by id desc
limit ".mysql_real_escape_string($start).",$recordsPerPage";
	  }
}
//echo $query;
$res    =   mysql_query($query);
$count  =   mysql_num_rows($res);
$HTML='';

   $HTML.='<table   width="100%">
	<tr style="background-color:#999999"><th colspan="4"><font size="5px" color="white"><b><center>Activity Report</center></b></font></th>

	</tr>
	</table><table  class="list-leaves" width="100%">
	<tr><td>SlNo:</td>
	<td>Project ID</td>
<td>Project Name</td>
	<td>Action</td>
	</tr>';
   
$rcnt=0;
if($count > 0)
{
    while($row=mysql_fetch_array($res))
    {
	 $rcnt=$rcnt+1;
	 
	 


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


 
	 
	 
        $post=$row['id'];
        $link=$row['id'];
        $HTML.='<tr class="expand_parent_row" style="cursor:pointer" id="parent_expand'.$rcnt.'" onclick="row_expan('.$rcnt.','.$count.')">';
        $HTML.='<td>'.$rcnt.'</td>';
	    $HTML.='<td>'.$resultproj['proj_id'].'</td>';
	    $HTML.='<td>'.$resultproj['proj_name'].'</td>';
	    $HTML.='<td>View</td>';

		?>
		
		
	<?php 
	
	
	
   $HTML.='</tr>'; 

   if($wek_ss)
   {
   $wek_from=date("Y-m-d",strtotime($wek_from));
   $wek_to=date("Y-m-d",strtotime($wek_to));
   //echo "select * from project_plan_activity where project_id='$row[project_id]' and week_no='$wek_ss' and dates_from='$wek_from' and dates_to='$wek_to'";
     if($userid!=1)
	 {
     $sub_loop=mysql_query("select * from project_activity_done where project_id='$row[project_id]' and week_id='$wek_ss'  and dat_from='$wek_from' and dat_to='$wek_to' and emp_id='$userid'");
	 }
	 else
	 {
	  $sub_loop=mysql_query("select * from project_activity_done where project_id='$row[project_id]' and week_id='$wek_ss'  and dat_from='$wek_from' and dat_to='$wek_to'");
	 }
   }
   else
   {
        if($userid!=1)
	    {
    $sub_loop=mysql_query("select * from project_activity_done where project_id='$row[project_id]' and emp_id='$userid'");
	    }
		else
		{
		$sub_loop=mysql_query("select * from project_activity_done where project_id='$row[project_id]' ");
		}
   }
   
   $HTML.=' <tr class="row_to_expand" style="display:none;" id="child_expand'.$rcnt.'">
			<td colspan="8">
				<table class="table table-bordered">
					<thead>
						<tr style="background-color:#fff;color:#000">
							<th style="width:50%;" colspan="7"><center><translate>View Details</translate></center></th>
						
						</tr>
					</thead>
					<tbody>
						<tr style="background-color:#fff;color:#000">
					<td>SlNo:</td>
					<td>Employee Name</td>
					<td>Date</td>
					<td>Activities Planned</td>
					<td>Hours Planned</td>
					<td>Task Details</td>
					<td>Hours Taken</td>
						</tr>';
						$s_cnt=0;
						$hrs=0;
			while($row_sub=mysql_fetch_array($sub_loop))
			{
			$hrs=$hrs+$row_sub['hourss'];
			$s_cnt=$s_cnt+1;
			$sub_resultproj = mysql_fetch_array(mysql_query("SELECT * FROM project_table where id='$row_sub[project_id]' "));
			$resultdsg = mysql_fetch_array(mysql_query("SELECT * FROM employee where e_id='$row_sub[emp_id]' "));
			
			$main_plan = mysql_fetch_array(mysql_query("SELECT * FROM project_plan_activity where id='$row_sub[p_act_id]' "));
			
			 $HTML.='<tr style="background-color:#fff;color:#000">';
			 $HTML.='<td>'.$s_cnt.'</td>';
             $HTML.='<td>'.$resultdsg['e_fname'].'</td>';
			
			 $HTML.='<td>'.date("d-m-Y",strtotime($row_sub['daily_dat'])).'</td>';
			 $HTML.='<td>'.$main_plan['activities'].'</td>';
			 $HTML.='<td>'.$main_plan['hourss'].'</td>';
			 $HTML.='<td>'.$row_sub['activities'].'</td>';
			 $HTML.='<td>'.$row_sub['hourss'].'</td>';
			 $HTML.='</tr >';
			}		
				$HTML.='<tr style="background-color:#fff;color:#000"><td colspan="6" align="right"><b>Total Hours:</b></td><td ><font color="red"><b>'.$hrs.' Hrs</b></font></td></tr>';		
						
					 $HTML.='</tbody>
				</table>
			</td>
		</tr>';
   }
	 
	$HTML.='</table>';
}
else
{
    //$HTML='No Data Found';
	
	$HTML='<table   width="100%">
	<tr style="background-color:#999999"><th colspan="4"><font size="5px" color="white"><b><center>View Details</center></b></font></th>

	</tr>
	</table>
	<table  class="list-leaves" width="100%">
	<tr><td>SlNo:</td>
	<td>Project ID</td>
<td>Project Name</td>

	<td>Action</td>
	</tr>
	<tr><td colspan="4" align="center"><font color="red"><b><center>There Is No Data Found</center></b></font></td></tr>';
	
}
echo $HTML;
echo $pagination;
?>