<?php session_name('CAKEPHP'); session_start();	
$PageSecurity = 1;
$tabindex=0;
//include('includes/DefinePaymentClass.php');
$title = _('Telephonic Order Memo');
include('includes/SQL_CommonFunctions.inc');
include('CRM/functions.php');
$s=new db_query();
$deptid=  $s->GetFieldValue('www_users'," id='".$_SESSION['UserID']."' " ,'mst_dpt_heirarchy');
$LowerDeptList=GETLowerDeptUser($_SESSION['UserID'],$deptid,$_SESSION['ACGCompanyId']);
$lowerlist=  UserDeptList($LowerDeptList);
 if(count($lowerlist)>0)
$lowerlist=implode(",",$lowerlist).",".$_SESSION['UserID'];
else
$lowerlist="'".$_SESSION['UserID']."'";


if($_REQUEST['Save']!='')
{
	$data['task_no']=$_REQUEST['task_no'];
	$data['start_date']=FormatDateForSQL($_REQUEST['start_date']);
	$data['start_time']=$_REQUEST['start_time'];
	$data['end_date']=FormatDateForSQL($_REQUEST['end_date']);
	$data['end_time']=$_REQUEST['end_time'];
	$data['repeat_status']=$_REQUEST['repeat_status'];
	$data['reminder_status']=$_REQUEST['reminder_status'];
	$data['reminder_time']=$_REQUEST['reminder_time'];
	$data['time_mode']=$_REQUEST['time_mode'];
	$data['assign_to']=$_REQUEST['assign_to'];
	$data['user_id']=$_REQUEST['user_id'];
	$data['task_description']=$_REQUEST['task_description'];
	$data['assigned_by']=$_SESSION['UserID'];
	$data['created']=date('Y/m/d');
	$data['created_by']=$_SESSION['UserID'];
	
	$sql1=$s->insertRecord('tsk_taskassignment', $data);
	$result1=DB_query($sql1,$db);
}

if($_REQUEST['Delete'])
{
	for($i=0;$i<count($_REQUEST['leadid']);$i++)
	{
	$condition="id='".$_REQUEST['leadid'][$i]."'";
	$s->DeleteRecord('tsk_taskassignment', $condition);
	}
	$s->pageLocation("index.php?route=TaskMgt/task_assign_index".$rurl);
}
?>
<script src="TaskMgt/ui/jquery.ui.timepicker.js"></script>
<style>
#showdata {
	display: block;
	background: url(TaskMgt/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>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div"> 
<h1>Task Assignment</h1>
  <form action="" method="post" name="myform" >
<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td class="tabledata1">Branch</td>
	<td colspan="3"><select name="site"  style="width:150px;">
<?php $Sitesql="select * from locations where  CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
	$SiteRes=DB_query($Sitesql,$db);
	while($SiteRow=DB_fetch_array($SiteRes)){?>
            <option value="<?php  echo $SiteRow['loccode'];?>" <?php  echo $_REQUEST['site']==$SiteRow['loccode']?'selected':''?> >
            <?php  echo $SiteRow['locationname'];?>
            </option>
<?php }?>
          </select>
	</td>
</tr>
<tr class="row1">
	<td class="tabledata1">From:</td>
	<td><input name="fromdate" type="text" style="width:150px;"  class="datepicker"/></td>
	<td class="tabledata1">To:</td>
	<td><input name="todate" type="text" style="width:150px;"  class="datepicker"/></td>
</tr>
<tr class="row1">
	<td style="text-align:center;" colspan="4">
	<input name="Search" type="submit" class="search"  value="Search"/>
	</td>
</tr>
<tr class="row1">
	<td colspan="4"><a href="<?php echo "index.php?route=TaskMgt/task_assign".$rurl.'&action=AddNew'?>">
				<input type="button" name="Create" value="Assign Task" class="search" /></a>
				<input type="submit" name="Delete" value="Delete" class="search" />
				<?php if($_REQUEST['Search']){ ?><a href="TaskMgt/TicketExp.php">
				<input type="button" name="Export" value="Export" class="search"  /></a>
	<?php }?>
	</td>
</tr>
<tr class="row1">
	<td colspan="4">
	<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr class="row1">
          <td class="tabledata"><input name="leadid" type="checkbox"   id="leadid" onclick="LeadData()"    /></td>
          <td class="tabledata">Branch</td>
          <td class="tabledata">Task No.</td>
		  <td class="tabledata">Start Date</td>
          <td class="tabledata">End Date</td>
		  <td class="tabledata">Assigned To</td>
		   <td class="tabledata">Task</td>
		  <td class="tabledata">Status</td>
 		 <td class="tabledata">Action</td>
</tr>
		<?php 
		$query = "SELECT * FROM tsk_taskassignment where assigned_by in($lowerlist) and CompanyId='".$_SESSION['ACGCompanyId']."'";
		$query .= " ORDER BY start_date desc";
		$gettt = DB_query($query,$db);
		$_SESSION['Ticket']=$query;
		$i=0;
		while($row_quotes = DB_fetch_array($gettt)){?>
		<tr class="row1">
			<td style="white-space:nowrap;" valign="top">
			<?php
			 $SOURL="index.php?route=TaskMgt/task_assign&action=Edit&id=".$row_quotes['id'].$rurl;
			 $REURL="index.php?route=TaskMgt/task_assign&action=SHRem&id=".$row_quotes['id'].$rurl;
			 //$SO_VIEW="index.php?route=TaskMgt/task_assign&action=View&ttid=".$row_quotes['id'].$rurl;
			?>
			   <input name="leadid[]" type="checkbox" id="leadid_<?php echo $i+1; ?>"   value="<?php  echo $row_quotes['id']?>"  />
			 <a href="<?php echo $SOURL ;?>"><img src="images/icon_edit.gif" width="10px"  height="10" /></a>
			 <!--<a href="<?php //echo $SO_VIEW?>" ><img src="images/search.gif" width="10px"  height="10" /></a>-->
		  </td>
          <td valign="top" ><?php  echo $s->GetFieldValue('locations',"loccode='".$row_quotes['branch']."'",'locationname'); ?></td>
          <td valign="top" style="white-space:nowrap"><?php echo $row_quotes['task_no'];?> </td>
          <td valign="top" style="white-space:nowrap"><?php echo ConvertSQLDate($row_quotes['start_date']);?> </td>
		  <td valign="top" ><?php echo ConvertSQLDate($row_quotes['end_date']);?></td>
          <td valign="top"><?php  if($row_quotes['assign_to']=='user'){echo $s->getField('www_users','id',$row_quotes['user_id'],'realname');;} else{echo $row_quotes['assign_to'];}//echo $s->GetFieldValue('www_users',"id='".$row_quotes['createdBy']."'",'userid'); ?></td>
		  <td valign="top"><?php echo $row_quotes['task_description'];?> </td>
			 <td valign="top"><?php echo $row_quotes['status'];?> </td>
			 <td valign="top"><a href="<?php echo $REURL ;?>">Show Remarks</a></td>
        </tr>
		<?php $i++;} ?>
        
      </table>
	</td>
</tr>
</table>
  </form>
</div></div>
 <script language="javascript" >
function LeadData()
{
	
	myCheckboxArray = document.myform.elements["leadid[]"];
	var t=myCheckboxArray.length;
	//alert(myCheckboxArray);
	if(document.getElementById('leadid').checked==true)
	{	
	if(t==undefined)
	document.getElementById('leadid_'+1).checked=true;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=true;	
	}	
	}
	else
	{
	if(t==undefined)		
	document.getElementById('leadid_'+1).checked=false;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=false;	
	}
	}
}
</script>