<?php
include 'connect/cms-config.php' ;
include 'requires/function.php' ;
include 'requires/session.php' ;

// include the class
include 'requires/class_resize.php' ;

// check permission
if ( !permissionCheck($row_user, 'setting') ){
	header('Location: index.php') ;
	exit ;
}

// keep parameter in value
$page = escapeString($_GET['page']) ;
$page_mode = escapeString($_GET['page_mode']) ;


if(isset($_POST['submit_month_setting'])){
	$month_setting = $_POST['month_setting'];
	$query_setting = $mysqli->query("SELECT * FROM setting_salary_tax WHERE tax_type = 'slip_month_setting' LIMIT 1");
	if(mysqli_num_rows($query_setting) <= 0){
		$update  = $mysqli->query("INSERT INTO setting_salary_tax( tax_title, tax_type) VALUES ('$month_setting','slip_month_setting')");
	}else{
		$result_setting = mysqli_fetch_assoc($query_setting);
		$setting_id = $result_setting['tax_id'];
		$update  = $mysqli->query("UPDATE setting_salary_tax SET tax_title = '$month_setting' WHERE tax_id = '$setting_id'");
	}
	if($update){
		$_SESSION['system_result'] = 'success-updated' ;
		header("Location:setting-slip.php?page_mode=all") ;
		exit ;
	}
}

$query_setting = $mysqli->query("SELECT * FROM setting_salary_tax WHERE tax_type = 'slip_month_setting' LIMIT 1");
if(mysqli_num_rows($query_setting) > 0){
	$result_setting = mysqli_fetch_assoc($query_setting);
}

// active menu bar
$active_main_menu = 'setting' ;
$active_sub_menu = 'setting-salary' ;
$active_menu = 'setting-slip' ;

// start header here
include 'requires/page_header.php';
include 'requires/page_top.php';

// mode type | all list | new | edit
switch($page_mode){
	
	// all hostel list
	case 'all' :
	default :
		?>
			<div class="warper container-fluid">   	
				<div class="page-header"><h1>Salary Slip <small>Setting</small></h1></div>
				<?php
	            if ($_SESSION['system_result'] != ''){
	                switch($_SESSION['system_result']){
	                    case 'success-updated' :
	                        echo '
	                        <div class="result_success">
	                            Thank you, the details have been saved.
	                        </div>' ;	
	                    break ;
	                }
	                unset($_SESSION['system_result']) ;
	            }
	            ?>
	            <div class="panel panel-default">
	                <div class="panel-heading"></div>
	                <div class="panel-body">
	                    <form method="post" class="form-horizontal" id="quotationForm" enctype="multipart/form-data" novalidate="novalidate">
	                        <div class="form-group">
	                            <div class="col-sm-2 control-label">Generate Salary slip for </div>
	                            <div class="col-sm-9" style="padding:4px; margin-left:10px">
	                                <select name="month_setting" class="chosen-select select2-basic-single form-control group_1">
	                                	<option value="current" <?= ($result_setting['tax_title']=='current' ? 'selected' : '') ?>>Current Month</option>
	                                	<option value="previous" <?= ($result_setting['tax_title']=='previous' ? 'selected' : '') ?>>Previous Month</option>
	                                </select>
	                            </div>
	                        </div>
	                        <div class="form-group">
	                            <div class="col-sm-2 control-label"></div>
	                            <div class="col-sm-9">
	                                <button type="submit" name="submit_month_setting" class="btn btn-purple" style="float:right"><?= $lang['submit'] ?></button>
	                                <input type="hidden" name="hide" value="1">
	                                <input type="hidden" name="page_status" value="<?= $submit_type ?>">
	                            </div>
	                        </div>   
	                    </form>
	                </div>
	            </div>
			</div>
		<?php
	break ;
}
// footer
include 'requires/page_footer.php' ;
?>