<?php
$table="hr_training_calendar";
$modid=isset($_REQUEST['modid'])?$_REQUEST['modid']:'';
$frmid=isset($_REQUEST['frmid'])?$_REQUEST['frmid']:'';
$rurl="index.php?route=HRModule/training_calender_index&modid=".$modid."&frmid=".$frmid;
$action=isset($_REQUEST['action'])?$_REQUEST['action']:'';
$ID=isset($_REQUEST['ID'])?(int)$_REQUEST['ID']:0;
$RData=array();
function htc($v){ return htmlspecialchars($v,ENT_QUOTES); }
function tc_req($k){ return isset($_REQUEST[$k])?addslashes(trim($_REQUEST[$k])):''; }
function tc_val($row,$k){ return isset($row[$k])?$row[$k]:''; }
function tc_date($k){ return (isset($_REQUEST[$k]) && trim($_REQUEST[$k])!='')?FormatDateForSQL($_REQUEST[$k]):'0000-00-00'; }
if(isset($_REQUEST['Save'])){
	$status=true;
	if(tc_req('event_name')==''){ $msgErr[]='Please Enter Event Name'; $status=false; }
	if(tc_req('event_date')==''){ $msgErr[]='Please Enter Event Date'; $status=false; }
	if($status){
		$data['calendar_year']=(int)tc_req('calendar_year');
		$data['calendar_month']=(int)tc_req('calendar_month');
		$data['target_group']=tc_req('target_group');
		$data['department']=(int)tc_req('department');
		$data['event_name']=tc_req('event_name');
		$data['event_date']=tc_date('event_date');
		$data['event_type']=tc_req('event_type');
		$data['duration_hours']=tc_req('duration_hours');
		$data['venue']=tc_req('venue');
		$data['seats_available']=(int)tc_req('seats_available');
		$data['status']=tc_req('status');
		$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 Calender</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 htc($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>Calendar Year</strong></td>
	<td width="20%"><input type="text" name="calendar_year" value="<?php echo htc(tc_val($RData,'calendar_year')!=''?tc_val($RData,'calendar_year'):date('Y')); ?>" style="width:98%;"></td>
	<td width="13%" align="right"><strong>Calendar Month</strong></td>
	<td width="20%"><select name="calendar_month" style="width:98%;">
		<?php $v=tc_val($RData,'calendar_month'); if($v==''){$v=date('n');} for($i=1;$i<=12;$i++){ ?><option value="<?php echo $i; ?>" <?php echo ($v==$i)?'selected':''; ?>><?php echo $i; ?></option><?php } ?>
	</select></td>
	<td width="13%" align="right"><strong>Target Group</strong></td>
	<td><select name="target_group" style="width:98%;"><?php $v=tc_val($RData,'target_group'); foreach(array('All Employees','New Joinee','Department Wise','Management','Staff') 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>Department</strong></td>
	<td><select name="department" style="width:98%;"><option value="0">Select</option>
		<?php $sel=tc_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 htc($r['deptname']); ?></option><?php } ?>
	</select></td>
	<td align="right"><strong>Event Name</strong></td>
	<td><input type="text" name="event_name" value="<?php echo htc(tc_val($RData,'event_name')); ?>" style="width:98%;"></td>
	<td align="right"><strong>Event Date</strong></td>
	<td><input type="text" name="event_date" class="datepicker" value="<?php echo (tc_val($RData,'event_date')!='0000-00-00' && tc_val($RData,'event_date')!='')?ConvertSQLDate(tc_val($RData,'event_date')):''; ?>" style="width:98%;"></td>
</tr>
<tr class="row1">
	<td align="right"><strong>Event Type</strong></td>
	<td><select name="event_type" style="width:98%;"><?php $v=tc_val($RData,'event_type'); foreach(array('Workshop','Induction','Compliance','Safety','Technical','Other') as $o){ ?><option value="<?php echo $o; ?>" <?php echo ($v==$o)?'selected':''; ?>><?php echo $o; ?></option><?php } ?></select></td>
	<td align="right"><strong>Duration Hours</strong></td>
	<td><input type="text" name="duration_hours" value="<?php echo htc(tc_val($RData,'duration_hours')); ?>" style="width:98%;"></td>
	<td align="right"><strong>Venue / Platform</strong></td>
	<td><input type="text" name="venue" value="<?php echo htc(tc_val($RData,'venue')); ?>" style="width:98%;"></td>
</tr>
<tr class="row1">
	<td align="right"><strong>Seats Available</strong></td>
	<td><input type="text" name="seats_available" value="<?php echo htc(tc_val($RData,'seats_available')); ?>" style="width:98%;"></td>
	<td align="right"><strong>Status</strong></td>
	<td><select name="status" style="width:98%;"><?php $v=tc_val($RData,'status'); if($v==''){$v='Active';} foreach(array('Active','Inactive') as $o){ ?><option value="<?php echo $o; ?>" <?php echo ($v==$o)?'selected':''; ?>><?php echo $o; ?></option><?php } ?></select></td>
	<td colspan="2">&nbsp;</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>
