<?php
$table="hr_training_schedule";
$modid=isset($_REQUEST['modid'])?$_REQUEST['modid']:'';
$frmid=isset($_REQUEST['frmid'])?$_REQUEST['frmid']:'';
$rurl="index.php?route=HRModule/training_schedule_index&modid=".$modid."&frmid=".$frmid;
$action=isset($_REQUEST['action'])?$_REQUEST['action']:'';
$ID=isset($_REQUEST['ID'])?(int)$_REQUEST['ID']:0;
$RData=array();
function hts($v){ return htmlspecialchars($v,ENT_QUOTES); }
function ts_req($k){ return isset($_REQUEST[$k])?addslashes(trim($_REQUEST[$k])):''; }
function ts_val($row,$k){ return isset($row[$k])?$row[$k]:''; }
function ts_date($k){ return (isset($_REQUEST[$k]) && trim($_REQUEST[$k])!='')?FormatDateForSQL($_REQUEST[$k]):'0000-00-00'; }
if(isset($_REQUEST['Save'])){
	$status=true;
	if((int)ts_req('training_id')==0){ $msgErr[]='Please Select Program'; $status=false; }
	if(ts_req('start_date')==''){ $msgErr[]='Please Enter Start Date'; $status=false; }
	if($status){
		$data['training_id']=(int)ts_req('training_id');
		$data['start_date']=ts_date('start_date');
		$data['end_date']=ts_date('end_date');
		$data['start_time']=ts_req('start_time');
		$data['end_time']=ts_req('end_time');
		$data['days_of_week']=ts_req('days_of_week');
		$data['trainer_name']=ts_req('trainer_name');
		$data['co_trainer']=ts_req('co_trainer');
		$data['venue']=ts_req('venue');
		$data['max_participants']=(int)ts_req('max_participants');
		$data['target_department']=(int)ts_req('target_department');
		$data['target_level']=ts_req('target_level');
		$data['enrollment_type']=ts_req('enrollment_type');
		$data['pre_requisite']=ts_req('pre_requisite');
		$data['special_instructions']=ts_req('special_instructions');
		$data['status']=ts_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 Schedule</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 hts($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>Program</strong></td>
	<td width="20%"><select name="training_id" style="width:98%;"><option value="0">Select</option>
		<?php $sel=ts_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 hts($r['program_name']); ?></option><?php } ?>
	</select></td>
	<td width="13%" align="right"><strong>Start Date</strong></td>
	<td width="20%"><input type="text" name="start_date" class="datepicker" value="<?php echo (ts_val($RData,'start_date')!='0000-00-00' && ts_val($RData,'start_date')!='')?ConvertSQLDate(ts_val($RData,'start_date')):''; ?>" style="width:98%;"></td>
	<td width="13%" align="right"><strong>End Date</strong></td>
	<td><input type="text" name="end_date" class="datepicker" value="<?php echo (ts_val($RData,'end_date')!='0000-00-00' && ts_val($RData,'end_date')!='')?ConvertSQLDate(ts_val($RData,'end_date')):''; ?>" style="width:98%;"></td>
</tr>
<tr class="row1">
	<td align="right"><strong>Start Time</strong></td>
	<td><input type="text" name="start_time" value="<?php echo hts(ts_val($RData,'start_time')!=''?ts_val($RData,'start_time'):'09:00'); ?>" style="width:98%;"></td>
	<td align="right"><strong>End Time</strong></td>
	<td><input type="text" name="end_time" value="<?php echo hts(ts_val($RData,'end_time')!=''?ts_val($RData,'end_time'):'17:00'); ?>" style="width:98%;"></td>
	<td align="right"><strong>Days of Week</strong></td>
	<td><input type="text" name="days_of_week" value="<?php echo hts(ts_val($RData,'days_of_week')); ?>" style="width:98%;" placeholder="Mon,Tue,Wed"></td>
</tr>
<tr class="row1">
	<td align="right"><strong>Trainer</strong></td>
	<td><input type="text" name="trainer_name" value="<?php echo hts(ts_val($RData,'trainer_name')); ?>" style="width:98%;"></td>
	<td align="right"><strong>Co-trainer</strong></td>
	<td><input type="text" name="co_trainer" value="<?php echo hts(ts_val($RData,'co_trainer')); ?>" style="width:98%;"></td>
	<td align="right"><strong>Venue</strong></td>
	<td><input type="text" name="venue" value="<?php echo hts(ts_val($RData,'venue')); ?>" style="width:98%;"></td>
</tr>
<tr class="row1">
	<td align="right"><strong>Max Participants</strong></td>
	<td><input type="text" name="max_participants" value="<?php echo hts(ts_val($RData,'max_participants')); ?>" style="width:98%;"></td>
	<td align="right"><strong>Target Department</strong></td>
	<td><select name="target_department" style="width:98%;"><option value="0">Select</option>
		<?php $sel=ts_val($RData,'target_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 hts($r['deptname']); ?></option><?php } ?>
	</select></td>
	<td align="right"><strong>Target Level</strong></td>
	<td><input type="text" name="target_level" value="<?php echo hts(ts_val($RData,'target_level')); ?>" style="width:98%;" placeholder="Junior, Mid-level"></td>
</tr>
<tr class="row1">
	<td align="right"><strong>Enrollment Type</strong></td>
	<td><select name="enrollment_type" style="width:98%;"><?php $v=ts_val($RData,'enrollment_type'); foreach(array('Open Enrollment','Nomination-based','Mandatory') as $o){ ?><option value="<?php echo $o; ?>" <?php echo ($v==$o)?'selected':''; ?>><?php echo $o; ?></option><?php } ?></select></td>
	<td align="right"><strong>Pre-requisite</strong></td>
	<td><input type="text" name="pre_requisite" value="<?php echo hts(ts_val($RData,'pre_requisite')); ?>" style="width:98%;"></td>
	<td align="right"><strong>Status</strong></td>
	<td><select name="status" style="width:98%;"><?php $v=ts_val($RData,'status'); if($v==''){$v='Planned';} foreach(array('Planned','Running','Completed','Cancelled') 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>Special Instructions</strong></td>
	<td colspan="5"><textarea name="special_instructions" style="width:99%;height:55px;"><?php echo hts(ts_val($RData,'special_instructions')); ?></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>
