sqlsafe('1'); switch ($act) { case 'addForm': if(!isset($_POST['depID'])){ $getDepartments = $db->select('select * from emp_departments order by fatherId ASC'); $countDep = count($getDepartments); for($i=0;$i<$countDep;$i++){ $getEmps = $db->CQuery('select count(id) from emp_personal_info where dep_id ='.$db->sqlsafe($getDepartments[$i]['id']).''); if($getEmps > 0){ $departments['Departments'][$getDepartments[$i]['id']]=getPath('emp_departments', $getDepartments[$i]['id'], $getDepartments[$i]['fatherId']); } } if(!is_array($departments)){ $skin = new skin(); $skin->assign('errorMSG','Sorry , There is no departments with valid number of employee, you may have departments but with no employee inside.'); $skin->assign('config',$config); $skin->assign('showMenu','1'); $skin->assign('incFile','site/error.tpl'); $skin->display('site/index.tpl'); }else{ $skin = new skin(); $skin->assign('config',$config); $skin->assign('showMenu','1'); $skin->assign('act','addForm'); $skin->assign('departments',$departments); $skin->assign('incFile','site/emp/dayOff_first.tpl'); $skin->display('site/index.tpl'); } }else{ $depId = $db->sqlsafe($_POST['depID']); $getAllEmployees = $db->select('select id , name from emp_personal_info where active='.$active.' and dep_id ='.$depId.' '); if(is_array($getAllEmployees)){ $countEmp = count($getAllEmployees); for($i=0;$i<$countEmp ; $i++){ $employees['Employees'][$getAllEmployees[$i]['id']]=$getAllEmployees[$i]['name']; } $skin = new skin(); $skin->assign('config',$config); $skin->assign('employee',$employees); $skin->assign('act','add'); $skin->display('site/emp/dayOff_second.tpl'); }else{ echo '
Sorry there is no employees in the choosen department
'; } } break; case 'add': if( empty($_POST['startDate']) OR empty($_POST['endDate']) OR !isset($_POST['depID']) OR !isset($_POST['empID']) ){ header('location: '.$config['url'].'/module.php?act=load&modload=employees&file=dayoff&action=addForm&error=1'); }else{ if(!isset($_POST['paid'])){ $paid = 0; }else{ $paid = $_POST['paid']; } $record = array( "emp_id"=>$db->sqlsafe($_POST['empID']), "dep_id"=>$db->sqlsafe($_POST['depID']), "start_date"=>$db->sqlsafe($_POST['startDate']), "end_date"=>$db->sqlsafe($_POST['endDate']), "paid"=>$db->sqlsafe($paid) ); $insert = $db->insert('emp_dayoff',$record); if($insert){ header('location: '.$config['url'].'/module.php?act=load&modload=employees&file=dayoff&action=addForm&error=3'); }else{ header('location: '.$config['url'].'/module.php?act=load&modload=employees&file=dayoff&action=addForm&error=2'); } } break; default: header('location: '.$config['url'].'/module.php?act=load&modload=employees&file=employee'); } ?>