<?php
$table="hr_training_details";
$modid=isset($_REQUEST['modid'])?$_REQUEST['modid']:'';
$frmid=isset($_REQUEST['frmid'])?$_REQUEST['frmid']:'';
$rurl="index.php?route=HRModule/training_details_index&modid=".$modid."&frmid=".$frmid;
$action=isset($_REQUEST['action'])?$_REQUEST['action']:'';
$ID=isset($_REQUEST['ID'])?(int)$_REQUEST['ID']:0;
$RData=array();
function htd($v){ return htmlspecialchars($v,ENT_QUOTES); }
function td_req($k){ return isset($_REQUEST[$k])?addslashes(trim($_REQUEST[$k])):''; }
function td_val($row,$k){ return isset($row[$k])?$row[$k]:''; }
function td_date($k){ return (isset($_REQUEST[$k]) && trim($_REQUEST[$k])!='')?FormatDateForSQL($_REQUEST[$k]):'0000-00-00'; }
if(isset($_REQUEST['Save'])){
	$status=true;
	if(td_req('employee_name')==''){ $msgErr[]='Please Enter Employee Name'; $status=false; }
	if(td_req('training_start_date')==''){ $msgErr[]='Please Enter Training Start Date'; $status=false; }
	if($status){
		$data['training_id']=(int)td_req('training_id');
		$data['employee_id']=(int)td_req('employee_id');
		$data['employee_code']=td_req('employee_code');
		$data['employee_name']=td_req('employee_name');
		$data['email']=td_req('email');
		$data['department']=(int)td_req('department');
		$data['designation']=td_req('designation');
		$data['joining_date']=td_date('joining_date');
		$data['reporting_manager']=td_req('reporting_manager');
		$data['work_location']=td_req('work_location');
		$data['induction_type']=td_req('induction_type');
		$data['trainer_name']=td_req('trainer_name');
		$data['training_start_date']=td_date('training_start_date');
		$data['training_end_date']=td_date('training_end_date');
		$data['topics_covered']=td_req('topics_covered');
		$data['completion_status']=td_req('completion_status');
		$data['certificate_issued']=td_req('certificate_issued');
		$data['remarks']=td_req('remarks');
		$data['modified_by']=$_SESSION['UserID'];
		$data['modified_date']=date('Y-m-d');
		if($action=='Edit' && $ID>0){
			$s->RecordEdit($table,$data,"id='".$ID."' and companyid='".$_SESSION['ACGCompanyId']."'");
			$s->pageLocation($rurl."&daction=Updated");
		}else{
			$data['created_by']=$_SESSION['UserID'];
			$data['created_date']=date('Y-m-d');
			$data['companyid']=$_SESSION['ACGCompanyId'];
			$s->RecordInsert($table,$data);
			$s->pageLocation($rurl."&daction=Inserted");
		}
	}
}
if($action=='Edit' && $ID>0){
	$SQL=DB_query("select * from ".$table." where id='".$ID."' and companyid='".$_SESSION['ACGCompanyId']."'",$db);
	$RData=DB_fetch_array($SQL);
}
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><strong>Training Details</strong></h1>
<?php if(isset($msgErr)){ ?><div class="error" style="text-align:center;"><?php for($i=0;$i<count($msgErr);$i++){ echo $msgErr[$i].'<br>'; } ?></div><?php } ?>
<form action="" method="post">
<input type="hidden" name="action" value="<?php echo htd($action); ?>">
<input type="hidden" name="ID" value="<?php echo $ID; ?>">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td width="13%" align="right"><strong>Training Program</strong></td>
	<td width="20%"><select name="training_id" style="width:98%;"><option value="0">Select</option>
		<?php $sel=td_val($RData,'training_id'); $q=DB_query("select id,program_name from hr_training_induction_master where companyid='".$_SESSION['ACGCompanyId']."' and status='Active' order by program_name",$db); while($r=DB_fetch_array($q)){ ?><option value="<?php echo $r['id']; ?>" <?php echo ($sel==$r['id'])?'selected':''; ?>><?php echo htd($r['program_name']); ?></option><?php } ?>
	</select></td>
	<td width="13%" align="right"><strong>Employee</strong></td>
	<td width="20%"><select name="employee_id" style="width:98%;"><option value="0">Select</option>
		<?php $sel=td_val($RData,'employee_id'); $q=DB_query("select id,emp_code,emp_name from empmaster where CompanyId='".$_SESSION['ACGCompanyId']."' order by emp_name",$db); while($r=DB_fetch_array($q)){ ?><option value="<?php echo $r['id']; ?>" <?php echo ($sel==$r['id'])?'selected':''; ?>><?php echo htd($r['emp_code'].' - '.$r['emp_name']); ?></option><?php } ?>
	</select></td>
	<td width="13%" align="right"><strong>Employee Code</strong></td>
	<td><input type="text" name="employee_code" value="<?php echo htd(td_val($RData,'employee_code')); ?>" style="width:98%;"></td>
</tr>
<tr class="row1">
	<td align="right"><strong>Employee Name</strong></td>
	<td><input type="text" name="employee_name" value="<?php echo htd(td_val($RData,'employee_name')); ?>" style="width:98%;"></td>
	<td align="right"><strong>Email</strong></td>
	<td><input type="text" name="email" value="<?php echo htd(td_val($RData,'email')); ?>" style="width:98%;"></td>
	<td align="right"><strong>Department</strong></td>
	<td><select name="department" style="width:98%;"><option value="0">Select</option>
		<?php $sel=td_val($RData,'department'); $q=DB_query("select id,deptname from deptmaster where CompanyId='".$_SESSION['ACGCompanyId']."' order by deptname",$db); while($r=DB_fetch_array($q)){ ?><option value="<?php echo $r['id']; ?>" <?php echo ($sel==$r['id'])?'selected':''; ?>><?php echo htd($r['deptname']); ?></option><?php } ?>
	</select></td>
</tr>
<tr class="row1">
	<td align="right"><strong>Designation</strong></td>
	<td><input type="text" name="designation" value="<?php echo htd(td_val($RData,'designation')); ?>" style="width:98%;"></td>
	<td align="right"><strong>Date of Joining</strong></td>
	<td><input type="text" name="joining_date" class="datepicker" value="<?php echo (td_val($RData,'joining_date')!='0000-00-00')?ConvertSQLDate(td_val($RData,'joining_date')):''; ?>" style="width:98%;"></td>
	<td align="right"><strong>Reporting Manager</strong></td>
	<td><input type="text" name="reporting_manager" value="<?php echo htd(td_val($RData,'reporting_manager')); ?>" style="width:98%;"></td>
</tr>
<tr class="row1">
	<td align="right"><strong>Work Location</strong></td>
	<td><input type="text" name="work_location" value="<?php echo htd(td_val($RData,'work_location')); ?>" style="width:98%;"></td>
	<td align="right"><strong>Induction Type</strong></td>
	<td><select name="induction_type" style="width:98%;">
		<?php $v=td_val($RData,'induction_type'); foreach(array('New Joinee','Department','Role Orientation','Refresher') as $o){ ?><option value="<?php echo $o; ?>" <?php echo ($v==$o)?'selected':''; ?>><?php echo $o; ?></option><?php } ?>
	</select></td>
	<td align="right"><strong>Trainer</strong></td>
	<td><input type="text" name="trainer_name" value="<?php echo htd(td_val($RData,'trainer_name')); ?>" style="width:98%;"></td>
</tr>
<tr class="row1">
	<td align="right"><strong>Start Date</strong></td>
	<td><input type="text" name="training_start_date" class="datepicker" value="<?php echo (td_val($RData,'training_start_date')!='0000-00-00')?ConvertSQLDate(td_val($RData,'training_start_date')):''; ?>" style="width:98%;"></td>
	<td align="right"><strong>End Date</strong></td>
	<td><input type="text" name="training_end_date" class="datepicker" value="<?php echo (td_val($RData,'training_end_date')!='0000-00-00')?ConvertSQLDate(td_val($RData,'training_end_date')):''; ?>" style="width:98%;"></td>
	<td align="right"><strong>Completion Status</strong></td>
	<td><select name="completion_status" style="width:98%;">
		<?php $v=td_val($RData,'completion_status'); foreach(array('Completed','Pending','In Progress') as $o){ ?><option value="<?php echo $o; ?>" <?php echo ($v==$o)?'selected':''; ?>><?php echo $o; ?></option><?php } ?>
	</select></td>
</tr>
<tr class="row1">
	<td align="right"><strong>Certificate Issued</strong></td>
	<td><select name="certificate_issued" style="width:98%;"><?php $v=td_val($RData,'certificate_issued'); foreach(array('No','Yes') as $o){ ?><option value="<?php echo $o; ?>" <?php echo ($v==$o)?'selected':''; ?>><?php echo $o; ?></option><?php } ?></select></td>
	<td align="right"><strong>Topics Covered</strong></td>
	<td colspan="3"><textarea name="topics_covered" style="width:99%;height:45px;"><?php echo htd(td_val($RData,'topics_covered')); ?></textarea></td>
</tr>
<tr class="row1">
	<td align="right"><strong>Remarks</strong></td>
	<td colspan="5"><textarea name="remarks" style="width:99%;height:50px;"><?php echo htd(td_val($RData,'remarks')); ?></textarea></td>
</tr>
<tr class="row1">
	<td colspan="6" align="center">
		<input name="Save" class="search" type="submit" value="Save" <?php if(($action=='Edit' && $_SESSION['frmEdit']=='0') || ($action!='Edit' && $_SESSION['frmcreate']=='0')){ ?>disabled<?php } ?>>
		<a href="<?php echo $rurl; ?>"><input type="button" value="Back" class="search"></a>
	</td>
</tr>
</table>
</form>
</div>
</div>
