<?php session_name('CAKEPHP'); session_start();	
$PageSecurity = 1;
$tabindex=0;
include('includes/DefinePaymentClass.php');
include('includes/SQL_CommonFunctions.inc');
include('CRM/functions.php');
$s=new db_query();
 if(count($lowerlist)>0)
$lowerlist=implode(",",$lowerlist).",".$_SESSION['UserID'];
else
$lowerlist="'".$_SESSION['UserID']."'";


$dept= $s->getField('www_users','id',$_SESSION['UserID'],'mst_dpt_heirarchy');
$dwn_team=GETLowerDeptUser($_SESSION['UserID'],$dept,$_SESSION['ACGCompanyId']);
$lowerlist=  UserDeptList($dwn_team);
//print_r($lowerlist1);
array_push($lowerlist,$_SESSION['UserID']);
//echo print_r($lowerlist1);
$timezone = new DateTimeZone("Asia/Kolkata" );
$date = new DateTime();
$date->setTimezone($timezone);
$current_time=$date->format('H:i:s');
if($_REQUEST['save']!='')
{
    
     $start=ConvertSqlDate($_REQUEST['start_date']).' '.$_REQUEST['start_time'] ;
     $end=ConvertSqlDate($_REQUEST['end_date']).' '.$_REQUEST['end_time'] ;
     
    DB_query(" insert into tsk_milestone_master (mile_name,assign_to,start_time,end_time,description,active_status,created_by,created_date,CompanyId) values('".$_REQUEST['mile_name']."','".$_REQUEST['assign_to']."','".$start."','".$end."','".$_REQUEST['mile_desc']."','".$_REQUEST['mile_status']."','".$_SESSION['UserID']."','".date('Y-m-d')."','".$_SESSION['ACGCompanyId']."')",$db);
    $s->pageLocation("index.php?route=TaskMgt/milestone_master".$rurl);  
    
}
?>
<link rel="stylesheet" type="text/css" href="css/jquery.datetimepicker.css"/>
<script src="ui/jquery.ui.timepicker.js"></script>
<link rel="stylesheet" href="css/new_mxerp.css">
<style>
#showdata {
	display: block;
	background: url(Default.png) no-repeat;
	top: 0px;
	left: 0px;
	width: 300px;
	min-height: 60px;
	z-index:0;
}
#back {
	display: none;
	top: 0px;
	left: 0px;
	width: 300px;
	min-height: 60px;
	z-index:0;
}
</style>
<?php if($_REQUEST['action']=='New'){ ?>
<div class="body_contain">
<div class="tab_div">
<h1>Milestone Master</h1>


<form action="" method="post" >
<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td class="tabledata1"><strong>Name</strong></td>
    <td><input type="text" name="mile_name" id="mile_name"></td>
</tr>
<tr class="row1">
          <td class="tabledata1"><strong>Description</strong></td>
          <td><textarea name="mile_desc" style="width:100%; height:50px;" id="mile_desc" placeholder="Milestone Description"></textarea></td>
        </tr>
<tr class="row1">
	<td class="tabledata1"><strong>Start Date & Time</strong></td>
	<td><input type="text" name="start_date" readonly="true" class="datetimepicker2"> <input type="text" name="start_time" class="datetimepicker1" > </td>
    
</tr>
<tr class="row1">
	<td class="tabledata1"><strong>End Date & Time</strong></td>
	<td><input type="text" readonly="true" name="end_date" class="datetimepicker2"> <input type="text" class="datetimepicker1" name="end_time" > </td>
         
</tr>
<tr class="row1">
	<td class="tabledata1"><strong>Assigned To</strong></td>
	<td><select name="assign_to">
                <?php //foreach($lowerlist as $val){  ?>
                <!--<option value="<?php echo $val; ?>"><?php echo  $s->getField('www_users','id',$val,'realname'); ?></option>-->
                <?php //} ?>
                 <option value="">Select</option>
		  <?php 
                 
		  $users=DB_query("Select * from www_users where companyid='".$_SESSION['ACGCompanyId']."' and vendorid='0' AND dealer IS NULL ",$db);
		  while($users_row=DB_fetch_array($users))
		  {?>
		  	<option value="<?php echo $users_row['id']?>"><?php echo $users_row['realname'];?></option>
		  <?php 	
		  }
		  ?>
            </select></td>
         
</tr>
<tr class="row1">
	<td class="tabledata1" ><strong>Active Status</strong></td>
		  
        <td style="width:250px;" >Active:&nbsp;<input type="radio" name="mile_status" id="mile_status" value="1" >&nbsp;&nbsp;&nbsp;Inactive &nbsp;<input type="radio" name="mile_status" id="mile_status" value="0" ></tr>

<tr class="row1">
    <td colspan="2" style="text-align:center;">
	<input name="save" type="submit" value="Save" onclick="javascript:return task_validate();" class="search" />
&nbsp;&nbsp;<input type="reset" value="Reset" class="search">&nbsp;&nbsp;<a href="index.php?route=TaskMgt/milestone_master&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>"><input type="button" value="Cancel" class="search"></a></td>
</tr>
</table>
    </form>

  </div>
</div>
<?php }  ?>
<script src="js/jquery111.js"></script>
<script src="js/jquery.datetimepicker.js"></script>

<script type="text/javascript" language="javascript">
function task_validate()
{
   var flag='0';
    var stat=document.getElementsByName("mile_status");
    for (var e=0;e<stat.length;e++) {
        if (stat[e].checked==true) {
            flag='1';
            break;
        }
    }
    var name=$("#mile_name").val();
   if(name=="")
    {
        alert("Please Enter Milestone name");
        return false;
    } 
if(flag=='0')
    {
    alert("Please Checked Active Status");    
    return false;
    }
    

}
$('.datetimepicker1').datetimepicker({
	datepicker:false,
	format:'H:i',
	step:5
});
$('.datetimepicker2').datetimepicker({
	timepicker:false,
	format:'d/m/Y',
	formatDate:'Y/m/d',
	//minDate:'-1970/01/02', // yesterday is minimum date
	//maxDate:'+1970/01/02' // and tommorow is maximum date calendar
});
</script>

<?php 


if($_REQUEST['action']==''){
?>
<div class="body_contain">
<div class="tab_div">
<h1>Milestone Master</h1>
<p style="text-align:left;"><a href="index.php?route=TaskMgt/milestone_master&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=New"><input type="button" style="margin-bottom:5px;" value="Add Milestone" class="search"></a></p>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 1px solid;">
    <tr>
        <th>Sr No.</th>
        <th>Name</th>
        <th>Created Date</th>
        <th>End Date</th>
        <th>Assigned To</th>
        <th>Status</th>
        
     </tr>
    <?php 
    $sql=DB_query("select mile_name,created_date,DATE(end_time) as d, end_time,active_status,assign_to from tsk_milestone_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
    $i=1;
   
   

    if(DB_num_rows($sql)>0){
    while($result=DB_fetch_assoc($sql)){ 
        ?>
        <tr><td><?php echo $i ?></td>
            <td><?php echo $result['mile_name'] ?></td>
            <td><?php echo ConvertSQLDate($result['created_date'])  ?></td>
            <td><?php  echo ConvertSQLDate($result['d']) ?></td>
             <td><?php echo  $s->getField('www_users','id',$result['assign_to'],'realname')?></td>
    <td><?php  if($result['active_status']=='1'){ echo "Active";} else if($result['active_status']=='0') {echo "Inactive";}  ?></td>
            
    <?php $i++; } } else { echo '<tr><td colspan="4">No Result Found.</td></tr>'; }
    ?>
     
</table>
<?php } ?>
</div>
</div>
