<?php 
//****************MODIFY BY AMIT SINGH ************D&D************************23-11-2012*********************************
$table='to_do';  include("CRM/ClassRole.php");
if($_REQUEST['DeleteRecord'])
{
	for($i=0;$i<count($_REQUEST['todo_leadid']);$i++)
	{
	$data['modified_date']=date('Y-m-d');
	$data['delete_status']='N';
	$cond="todoid='".$_REQUEST['todo_leadid'][$i]."'";
	$row= $s->RecordEdit($table, $data,$cond);
	}
}


if($_REQUEST['Save'])
{
	$fstatus=true;
	if($_REQUEST['leadtodo']=='')
	{
	$msgErr[]="Please Enter The To Do";
	$fstatus=false;
	}
	if($_REQUEST['todostatus']=='0')
	{
	$msgErr[]="Please Select The Status";
	$fstatus=false;
	}
	if($_REQUEST['lead_priority']=='0')
	{
	$msgErr[]="Please Select The  Priority";
	$fstatus=false;
	}
	if($_REQUEST['tododue_date']=='')
	{
	$msgErr[]="Please Select The Due Date";
	$fstatus=false;
	}
	if($_REQUEST['tododatetime']=='')
	{
	$msgErr[]="Please Enter The To Do Date";
	$fstatus=false;
	}
}


if($_REQUEST['Save'] && $fstatus)
{
	$data['due_date']=FormatDateForSQL($_REQUEST['tododue_date']);
	$data['to_do']=$_REQUEST['leadtodo'];
	$data['periority']=$_REQUEST['lead_priority'];
	$data['description']=htmlspecialchars($_REQUEST['description'],ENT_QUOTES);
	$data['date1']=FormatDateForSQL($_REQUEST['tododatetime']);
	$data['status1']=$_REQUEST['todostatus'];
	$data['group1']=trim(implode(',',$_REQUEST['groupid']));
	$data['user1']=trim(implode(',',$_REQUEST['leaduserid']));
	$data['time1']=$_REQUEST['hours'].":".$_REQUEST['mins']." ".$_REQUEST['AMPM'];
        
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	$data['created_date']=date('Y-m-d');
	$data['created_by']=$_SESSION['UserID'];
	
	if($_REQUEST['action']=='Edit')
	{
	$cond="id='".$_REQUEST['id']."'";
	$row= $s->RecordEdit($table, $data,$cond);
	}
	else{
           
	DB_query("insert into evenement (title,start,end,url) values('TODO-".$_REQUEST['leadtodo']."','".FormatDateForSQL($_REQUEST['tododatetime'])."','".FormatDateForSQL($_REQUEST['tododue_date'])."','".$_REQUEST['leadtodo']."')",$db );  
	$row= $s->RecordInsert($table, $data);
	}
	$s->pageLocation("index.php?route=TaskMgt/TODO".$rurl);
}	



if($_REQUEST['action']=='Edit')
{
	$sqlget=DB_query("select * from to_do where id='".$_REQUEST['id']."'",$db);
	$FetchData=DB_fetch_array($sqlget);
	extract($FetchData);
	$timemin=explode(" ",$time1);
	$hours=explode(":",$timemin[0]);
}	 





if($_REQUEST['action']=='View')
{//
//	$condition="todoid='".$_REQUEST['todoid']."' and mst_leadid='".$_REQUEST['leadid']."'";
//	$rec=$s->GetRecordById('crm_leadtodo',  $condition);
//	$recRow=DB_fetch_array($rec);
//	extract($recRow);
}

?>
<link rel="stylesheet" type="text/css" href="css/jquery.datetimepicker.css" />
<script language="javascript" >
function LeadData()
{	
	myCheckboxArray = document.myform.elements["todo_leadid[]"];
	var t=myCheckboxArray.length;
	if(document.getElementById('todo_leadid').checked==true)
	{	
	if(t==undefined)
	document.getElementById('todo_leadid_'+1).checked=true;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('todo_leadid_'+i).checked=true;	
	}	
	}
	else
	{
	if(t==undefined)		
	document.getElementById('todo_leadid_'+1).checked=false;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('todo_leadid_'+i).checked=false;	
	}
	}
	
	
	
}
</script>
<?php  
//include('crm_top_menu.php'); ?>
<div style="width:100%">
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Create To Do</h1>
<form name="form1" method="post" action="">
<input name="mst_leadid" type="hidden" value="<?php  echo $_REQUEST['leadid']?>">
<input name="lead_type" type="hidden" value="Task">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
 <?php if(count($msgErr)>0){?>
	  <tr class="row1">
	<td colspan="6"><?php for($i=0;$i<count($msgErr);$i++){
		echo "<div class='error'>".$msgErr[$i]."</div>";}?>
		</td>
		</tr><?php }?>
	  <tr class="row1" valign="top">
	    <td class="tabledata1">To Do<label><font color="#FF0000">*</font></label> </th>
	    <td><input type="text" name="leadtodo" value="<?php echo $to_do?>" style="width:425px;"></td>
	    </tr>
	   <tr class="row1" valign="top">
	    <td class="tabledata1">Description</th>
	    <td><textarea name="description" cols="50" rows="5"><?php echo $description?> </textarea> </td>
	    </tr>
	  <tr class="row1">
	     <td class="tabledata1" colspan="2">
		<table width="100%" border="0">
		  <tr class="row1">
			<td class="tabledata1"><strong>Status<label><font color="#FF0000">*</font></label> </strong></td>
			<td class="tabledata1"><strong>Priority <label><font color="#FF0000">*</font></label></strong> </td>
			<td class="tabledata1"><strong>Due Date<label><font color="#FF0000">*</font></label></strong> </td>
			
		  </tr>
		  <tr class="row1">
		    <td> <select name="todostatus">
		    	<option value="0">--Select--</option>
		    	<option  value="Pending" <?php echo  $status1=='Pending'?'selected':'' ;?>  >Pending</option>
		    	<option value="Confirm"  <?php echo  $status1=='Confirm'?'selected':'' ;?>>Confirm</option>
		    	
		    </select>  </td>
		    <td>
			<select style="width:150px;" name="lead_priority">
					<option value="0">--Select--</option>
					<option value="High" <?php  echo ($periority=='High'?'selected':'')?>>High</option>
					<option value="Low" <?php  echo ($periority=='Low'?'selected':'')?>>Low</option>
					<option value="Medium" <?php  echo ($periority=='Medium'?'selected':'')?>>Medium</option>
		</select></td>
		   <td><input type="text" name="tododue_date" class="datetimepicker2" value="<?php  echo date('d/m/Y');?>" style="width:150px;"></td>
		    </tr>
		    <tr class="row1">
		    	
		    	<td class="tabledata1">Group<label><font color="#FF0000">*</font></label></th>
              <td width="22%"><?php echo $ClassRole->Role($group1);?></td>
              <td class="tabledata1">User<label><font color="#FF0000">*</font></label></td>
              <td width="19%"><div id='hid-Roleid'>
<?php  
 
 $user=explode(',',$user1);
 $sql_state=DB_query("SELECT id , realname FROM  www_users where rolepid ='".$group1."' ",$db);		

while($row=DB_fetch_array($sql_state))
{
$p='';
if (in_array($row['id'],  $user))
$p='checked';
?>
<input name="leaduserid[]" type="checkbox" value="<?php  echo $row['id'];?>"  <?php echo $p;?>   /><?php  echo $row['realname'];?><br />
 <?php 
 }
if(!$user1)
{
 echo "<select name='leaduserid[]' style='width:150px;'  >";
 echo "<option value='000'>---</option>";
 echo "</select>";
}	
?>	
	</div></td>
		    	
		    </tr>
		  <tr class="row1">
		    <td class="tabledata1"><strong>Time &amp; Date<label><font color="#FF0000">*</font></label></strong> </td>
		    <td>&nbsp;</td>
		    
		    </tr>
		  <tr class="row1">
		    <td class="tabledata1">
			<input type="text" class="datetimepicker1" >
                    </td>
			<td>
			<input type="text" name="tododatetime" class="datetimepicker2" value="<?php  echo date('d/m/Y');?>" style="width:130px;">&nbsp;</td>
		    <td>&nbsp;</td>
		    
		    </tr>
		  <tr>
		    <td style="text-align:center;" colspan="4">
		      <input type="submit" name="Save" value="<?php if($_REQUEST['action']=='Edit'){ echo 'Update';} else{echo 'Save';} ?>" class="search">
		      
		    </td>
		    <td>&nbsp;</td>
		    <td>&nbsp;</td>
		    </tr>
		</table>
</td>
	    </tr>
	</table>
</form>


</div></div>

<script src="js/jquery111.js"></script>
<script src="js/jquery.datetimepicker.js"></script>
<script>

$('.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>