<!DOCTYPE html>
<html>
    <head>
<?php include("header-js.php");?>	
		
		
<!-----hrm-------------->		
<?php /*?><link rel="stylesheet" href="css/style.css" />
<!-- Responsive -->
<link rel="stylesheet" href="css/responsive.css" /><?php */?>
<link rel="stylesheet" href="css/jquery-ui.css" />
<!-----hrm-------------->
        <link href="css/AdminLTE_activity.css" rel="stylesheet" type="text/css" />

    
    </head>
    <body class="skin-blue">
       <?php include("header.php");?>
				<?php include("activity_header.php");?><!--grey_bg-->
				
			
				
				
		<form name="planact" id="planact" action="" method="post" style="width:100%">		
				
				<div class="clearfix"></div>
				
				<div class="project_button_area">
				
				<div class="blue_header_activityplan">
				
				<div class="activityplan_header_div">
				
			<div class="activityplan_header_div">
				
								<div class="week_activityplan_text">	<font color="#FFFFFF" size="4px"><b>Activity Plan</b></font> </div>
			
				  </div>
								
				  </div><!--activityplan_header_div-->
						<?php if($userid==1){?>			
								<div class="activityplan_select_week_div">
								
								
								
								<div class="week_activityplan_allign">

				
				<div class="week_activityplan_text">Select Week</div>
				
										<div class="week_activityplan">
<?php		$year           = date('Y');
$firstDayOfYear = mktime(0, 0, 0, 1, 1, $year);
$nextMonday     = strtotime('monday', $firstDayOfYear);
$nextSunday     = strtotime('sunday', $nextMonday);

?>
								
								<select name="wek_set" id="wek_set">
	<?php 
	
	$cnts=0;
while (date('Y', $nextMonday) == $year) {$cnts=$cnts+1;
    // date('d-m-Y', $nextMonday), '-', date('d-m-Y', $nextSunday).'<br />';

    $nextMonday = strtotime('+1 week', $nextMonday);
    $nextSunday = strtotime('+1 week', $nextSunday);
	?><?php } ?>
  <option value="1">1</option>


</select>
								
								
								</div><!--week_activityplan-->
								
								
								
								</div><!--week_activityplan_allign-->
								
								
								<div class="week_activityplan_allign">
								
								
								<div class="week_activityplan_text">Define week Date</div>
								
								
								</div><!--week_activityplan_allign-->
								
								
								
								<div class="week_activityplan_allign">
								
								
								
																<div class="week_activityplan_text">From</div>
		<?php $num_val = mysql_fetch_array(mysql_query("SELECT * FROM project_plan_master "));?>
								
								
								<div class="week_activityplan">
								
								<input type="hidden" id="hid_mast_dat" name="hid_mast_dat" value="<?php echo date("d-m-Y",strtotime($num_val['date_from']));?>">
								
								<?php if($num_val['date_from']!=''){?>
<input type="text" name="resi_dats" id="resi_dats" value="<?php echo date("d-m-Y",strtotime($num_val['date_from']));?>" style="border:0px;" readonly  />					
			<?php } else {?>	
			<div id="new_crt_dv">
			
			<input type="text" name="resi_dats" id="resi_dats" value="" readonly class="resi_dat" onChange="mastdate(this);" style="visibility:visible" />	
			
		<!--	<input type="text" value="" id="hid_dat" name="hid_dat" style="visibility:hidden">-->
		</div>
			
			<?php } ?>				
								</div><!--week_activityplan-->
								
								<div class="week_activityplan_text">to</div>
								
								
																<div class="week_activityplan">
																	<?php if($num_val['date_to']!=''){?>
								
<input type="text" name="wek_end" id="wek_end" value="<?php echo date("d-m-Y",strtotime($num_val['date_to']));?>" style="border:0px;"    readonly/>					
					<?php } else {?>
					<input type="text" name="wek_end" id="wek_end" value="" style="border:0px;"    readonly/>			
								<?php } ?>					
								</div><!--week_activityplan-->
								
								
								</div><!--activityplan_select_week_div-->
								
								</div><!--week_activityplan_allign-->
								
					<?php }?>			
		
		<?php if($userid!=1){?>						
				<?php $num_val = mysql_fetch_array(mysql_query("SELECT * FROM project_plan_master "));?>
												<?php if($num_val['date_from']!=''){?>
<input type="hidden" name="resi_dats" id="resi_dats" value="<?php echo date("d-m-Y",strtotime($num_val['date_from']));?>" style="border:0px;" readonly  />	
<input type="hidden" name="wek_end" id="wek_end" value="<?php echo date("d-m-Y",strtotime($num_val['date_to']));?>" style="border:0px;"    readonly/>						
			<?php } else {?>	
			
			<input type="hidden" name="resi_dats" id="resi_dats" value="" style="border:0px;" readonly class="resi_dat" onChange="mastdate(this);"  />	
			<input type="hidden" name="wek_end" id="wek_end" value="" style="border:0px;"    readonly/>	
			
			<?php } ?>	
			<?php } ?>	
				
				</div><!--blue_header_activityplan-->
								
				</div><!--project_button_area-->
				
		
								<div class="add_project_div_activityplan">
								
								<div class="project_free_div_activityplan">
								
								
																<div class="week_activityplan_allign">

				
				<div class="week_activityplan_text2">Week &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
				
				
				
										<div class="week_activityplan" id="wek_act_plan">
								
<?php	
$dat_cnt=date("W", mktime(0,0,0,12,28,date('Y')));
	$year           = date('Y');
$firstDayOfYear = mktime(0, 0, 0, 1, 1, $year);
$nextMonday     = strtotime('monday', $firstDayOfYear);
$nextSunday     = strtotime('sunday', $nextMonday);

?>
								
								<select name="wek_usr" id="wek_usr">
							
	<?php 
	
	$cnts=0;
//while (date('Y', $nextMonday) == $year) {$cnts=$cnts+1;
for($h=1;$h<=$dat_cnt;$h++){
    // date('d-m-Y', $nextMonday), '-', date('d-m-Y', $nextSunday).'<br />';

   
	?>
  <option value="<?php echo $h;?>"><?php echo $h;?></option>
<?php } ?>

</select>		
								
								</div><!--week_activityplan-->
								
								
								
								</div><!--week_activityplan_allign-->
								
								
								<div class="activityplan_select_week_div_bottom_closediv">
								
								<div class="activityplan_select_week_div_bottom">
								
												<div class="week_activityplan_text4">From</div>
												
												<div class="form_div_2">
				
<?php if($num_val['date_from']==''){?>
<input type="text" name="wek_from" id="wek_from" value=""   readonly>
<?php } else {?>
<input type="text" name="wek_from" id="wek_from" value="<?php echo date("d-m-Y",strtotime($num_val['date_from']));?>"   readonly>
<?php } ?>
				</div>
												
												
								  </div>
												
												
								  </div>
												
																									<div class="activityplan_select_week_div_bottom_closediv">

												
												
																<div class="activityplan_select_week_div_bottom">
								
												<div class="week_activityplan_text3">To</div>
												
												<div class="form_div_2">
		<!--class="resi_dat"-->
		<?php if($num_val['date_to']==''){?>
<input type="text" name="wek_to" id="wek_to" value=""   readonly>
<?php } else {?>
<input type="text" name="wek_to" id="wek_to" value="<?php echo date("d-m-Y",strtotime($num_val['date_to']));?>"   readonly>
<?php }?>
				</div>
												
												
												</div>
												
												
												</div>
												
												

												
																								
								
								
								
								
								</div><!--project_free_div_activityplan-->
								
			<hr>
          <?php $projects_current = $db->fetchQuery("SELECT * FROM project_table  order by id desc ");?>
			<?php $projects_all = $db->fetchQuery("SELECT * FROM project_table  order by id desc ");?>
								
				<div class="project_free_div">
	<table  class="list-leaves add-activity" width="100%">
	<tr><td>SlNo:</td>
	<td>Project ID</td>
<td>Project Name</td>
	<td>Date</td>
	<td>Activities Planned</td>

	<td>Hours</td></tr>

<tr class="m_tr" id="m_tr0">
<td id="slnoo0" class="activity-slno">1</td>
<td><select name="proj_ids[]" id="proj_ids1" style="width:136px;" class="proj_clss" data-id="1" >	
<option value="">Select Project Id</option>			
<?php foreach($projects_current as $all_proj){?>
<option value="<?php echo $all_proj['id'];?>"><?php echo $all_proj['proj_id'];?></option>
<?php } ?>
</select></td>
<td>			<select name="proj_name[]" id="proj_name1" style="width:136px;" class="projname_clss" data-id="1">
			<option value="">Select Project Name</option>				
<?php foreach($projects_all as $all_projts){?>
<option value="<?php echo $all_projts['id'];?>"><?php echo $all_projts['proj_name'];?></option>
<?php } ?>
</select></td>
<td>	<div class="form_div_3_activitiesdone datesdiv" id="sel_divcxz">


				</div></td>
<td><input type="text" name="act_vity[]" id="act_vity1" value="" class="actss"></td>



<td>
<select name="hurs[]" id="hurs1" style="width:135px;" class="hrss">
<option value="">Select</option>
<?php for($r=1;$r<=24;$r++){?>
<option value="<?php echo $r;?>"><?php echo $r;?> hr</option>
<?php }?>
</select>

</td>

</tr>	
			</table>	
				</div>
				
				<div class="clearfix"></div>
				
				<div class="button_position">
				
			<div class="add_more_img" style="margin-top: 3px !important;width: 79px  !important;">
				<a href="javascript:void(0)" onClick="clone_dv();"><img src="images/demo_1.jpg"></a>
				</div><div class="add_projects"><button type="button" class="add_projects" id="savclick" onClick="save_projp();">Submit</button></div>
												
				  </div>

				
				
				</div>

		<input type="hidden" name="useridss" id="useridss" value="<?php echo $userid;?>">
			</form>	
		
				

				<section>
                
				<div class="project_id_activityplan">
        
			
            <div id="m_divs">

				
				
			</div>
            	
				</div>

				
				
				
				</section>
				
				<div class="clearfix"></div>
				
				

                </section><!-- /.content -->
            </aside><!-- /.right-side -->
        </div><!-- ./wrapper -->


        <!-- jQuery 2.0.2 -->
		               <?php 
	include("footer-js.php");
?>
<input type="hidden" name="hid_week" id="hid_week" value="<?php echo $weekNumber = date("W"); ?>">
<input type="hidden" name="r_cnts" id="r_cnts" value="1">

    </body>
	



<link rel="stylesheet" href="css/jquery.ui.all.css">


<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/jqueryresigned-emp-ui.js"></script>
<!-- Jquery Package End -->
	<script src="js/activity.js" type="text/javascript"></script>
	
	
	<script type="text/javascript">
	
	
	function save_projp()
	{
		
	$count = $('.add-activity tr').length-1; 
		var alr=false; 

	for(q=1;q<=$count;q++)
	{
	 var acts=$('#act_vity'+q).val(); 
	 var hrs=$('#hurs'+q).val();
	 var prj=$('#proj_ids'+q).val();
	 
	 
	 
	   if(acts!='' && hrs!='' && prj!='')
		  {
		  var alr=true;
		  }
		  else
		  {
		     if(acts=='')
			 {
		     document.getElementById("act_vity"+q).style.background="pink";
		     }
			  if(hrs=='')
			 {
		     document.getElementById("hurs"+q).style.background="pink";
		     }
			 if(prj=='')
			 {
		     document.getElementById("proj_ids"+q).style.background="pink";
		     }
		 }
	}
		
			if(alr == false)
	{

	alert("Please Enter Atleast One Activity");
	}
	else
	{
		

		$('#savclick').attr('disabled',true);
	dataString = $('#planact').serialize(); //alert(dataString);

$.post("project_plan_add.php?action=grt_insert",dataString,function(data){
		var timing = data.timing;
		alert("Activity Plan Added Successfully");
		history.go(0);
	window.document.location.reload();

		},'json');		
		

	
	
		
		
		
}	
		
	}
	</script>
	<style>
div.pagination {
padding: 3px;
margin: 3px;
text-align:center;
}

div.pagination a {
padding: 2px 5px 2px 5px;
margin: 2px;
border: 1px solid #AAAADD;

text-decoration: none; /* no underline */
color: #000099;
}
div.pagination a:hover, div.digg a:active {
border: 1px solid #000099;

color: #000;
}
div.pagination span.current {
padding: 2px 5px 2px 5px;
margin: 2px;
border: 1px solid #B0B7D1;

font-weight: bold;
background-color: #939399;
color: #FFF;
}
div.pagination span.disabled {
padding: 2px 5px 2px 5px;
margin: 2px;
border: 1px solid #EEE;

color: #DDD;
}

</style>
		<script type="text/javascript">
$(document).ready(function(){
changePagination('0');    
});
function changePagination(pageId){
var users='<?php echo $userid;?>';
     $(".flash").show();
     $(".flash").fadeIn(400).html
                ('Loading <img src="ajax-loader.gif" />');
     var dataString = 'pageId='+ pageId+'&userid='+users;
     $.ajax({
           type: "POST",
           url: "loadplandata.php",
           data: dataString,
           cache: false,
           success: function(result){
           $(".flash").hide();
                 $("#m_divs").html(result);
           }
      });
}

function mastdate(dats)
{
var datFrm=dats.value;
var datTo=$('#wek_end').val();

var x = confirm("Are you sure you want to Set The Date As First Week?");
if(x==true)
{
 //document.getElementById("hid_dat").style.visibility="visible";
 //document.getElementById("hid_dat").value=datFrm;
//document.getElementById("resi_dats").style.visibility="hidden";
$('#resi_dats').remove();
//week_activityplan
$("#new_crt_dv").append('<input type="text" id="resi_dats" name="resi_dats" value="'+datFrm+'" readonly>');


     var dataString = 'frm='+datFrm+'&tos='+datTo;
     $.ajax({
           type: "POST",
           url: "loadactmasterdate.php",
           data: dataString,
           cache: false,
           success: function(result){
           		$(".flash").hide();
                // $("#m_divs").html(result);
           }
      });
}
else{
$('#resi_dats').val('');
$('#wek_end').val('');
$('#wek_from').val('');
$('#wek_to').val('');
}

}

	
	$('#proj_ids').on('change', function() {
 $('#savclick').attr('disabled',false);
});

	$('#proj_name').on('change', function() {
 $('#savclick').attr('disabled',false);
});

	$('#assign_to').on('click', function() {
  $('#savclick').attr('disabled',false);
});


var wek_val=$('#hid_week').val();
/*$('#wek_usrs_ft').val(wek_val);*/

var users='<?php echo $userid;?>';
change_week_activity_plan(wek_val,users);

go_to_cal();


function go_to_cal()
{
var to_dat=$('#wek_to').val();
var from_dat=$('#wek_from').val();

     var dataString = 'too='+ to_dat+'&frmm='+from_dat+'&act=plan'; 
     $.ajax({
           type: "POST",
           url: "loadact_daily_dat.php",
           data: dataString,
           cache: false,
           success: function(result){
           $(".flash").hide();
                 $(".datesdiv").html(result);
           }
      });

}





$count = 2;

function clone_dv(){
		$clone = $('.m_tr:first').clone(true);
		$clone.find('input').val('');
		$clone.find('.projname_clss').attr('id','proj_name'+$count);
		$clone.find('.projname_clss').attr('data-id',$count);
		
		$clone.find('.proj_clss').attr('id','proj_ids'+$count);
		$clone.find('.proj_clss').attr('data-id',$count);
		
		$clone.find('.actss').attr('id','act_vity'+$count);
		//$clone.find('.actss').attr('data-id',$count);
		$clone.find('.hrss').attr('id','hurs'+$count);
		
		$clone.find('td.activity-slno').text($count);
		$parent = $('.add-activity');
		$parent.append($clone);
		$count++;
}
	


	$('.proj_clss').on('change', function() {
 var ids=$(this).attr("data-id");
 var p_id=$(this).val(); 
 $('#proj_ids'+ids).val(p_id);
 $('#proj_name'+ids).val(p_id);
});


	$('.projname_clss').on('change', function() {
 var ids=$(this).attr("data-id");
 var p_id=$(this).val(); 
 $('#proj_ids'+ids).val(p_id);
 $('#proj_name'+ids).val(p_id);
});


function sort_act_list(obj)
{

var wekss=obj.value;
var pageId=0;
   var users='<?php echo $userid;?>';
     var dataString = 'pageId='+ pageId+'&userid='+users+'&weks='+wekss;
     $.ajax({
           type: "POST",
           url: "loadplandata.php",
           data: dataString,
           cache: false,
           success: function(result){
           $(".flash").hide();
                 $("#m_divs").html(result);
           }
      });

}

</script>
	
</html>