<?php
	//Start session
	session_start();
	
	//Include database connection details
	require_once('db_connect.php');
	
	//Array to store validation errors
	$errmsg_arr = array();
	
	//Validation error flag
	$errflag = false;
	

	
	//Function to sanitize values received from the form. Prevents SQL injection
	
	
	//Sanitize the POST values
	$Username = clean($con,$_POST['loginname']);
	$Password = clean($con,$_POST['pwd']);
	$fny = $_POST['fny'];
	$cmp1 = $_POST['cmp'];
	
	if($cmp1=="GD-GEETEE DECORS PVT. LTD.")
	{
	
	$cmpc="GD";
	$cmp="GEETEE DECORS PVT. LTD.";
	
	//company address here
	$cmpadd1=" 504-505, Aditya Heritage, Om Nagar, JB Nagar, Andheri (E), Mumbai - 400 099 ";
	$cmpadd1_1=" 9833455013 * info@geeteedecors.com * http://www.geeteedecors.com ";
	
	//help line no here
	$helpline_no="9833455013";
	
	//panno no here
	$pan_no="AALCG4637M";
	
	//sertaxno  no here
	$sertax_no="27AALCG4637M1Z1";
	
	//sms username here
	$smsuser_no="";
	
	//sms pwd no here
	$smspwd_no="";
	
	//sms sid  no here
	$smssid_no="";
	
	/*
	set ds_details
	* on= show ds details on next page
	* off= show ds details on same page
	* none= dont print ds details 
	*/
	$ds_details="off";
	
	//#set pre_printed to off if company  want bill in preprinted format  otherwise set to on
	$pre_printed="off";
	
	#set show_logo to off if company  want bill without logo  otherwise set to on
	$show_logo="on";
	
	//mail details for log entry
	$mail_from="info@geeteedecors.com";
	$mail_to="geeteedecors@outlook.com";
	
	
	$cmpadd2=" 504-505, Aditya Heritage, Om Nagar, JB Nagar, Andheri (E), Mumbai - 400 099 ";
	$cmpadd2_1=" 9833455013 * info@geeteedecors.com * http://www.geeteedecors.com ";
	}
	//Input Validations
	
	if($Username == '') {
		$errmsg_arr[] = 'Username missing';
		$errflag = true;
	}
	if($Password == '') {
		$errmsg_arr[] = 'Password missing';
		$errflag = true;
	}

	
	//If there are input validations, redirect back to the login form
	//if($errflag) {
//		$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
//		session_write_close();
//		header("location: bookinglogin.html");
//		exit();
//	}
	
	//Create query
	$qry="SELECT * FROM usermst WHERE loginname='$Username' AND pwd='$Password'";
	$result=mysqli_query($con,$qry);
	
	//Check whether the query was successful or not
	if($result) {
		if(mysqli_num_rows($result) == 1) {
			//Login Successful
			session_regenerate_id();
			$member = mysqli_fetch_assoc($result);
			$_SESSION['SESS_ROOTPATH'] = "http://$_SERVER[SERVER_NAME]/invsol/";
			$_SESSION['SESS_MEMBER_ID'] = $member['userid'];
			$_SESSION['SESS_FIRST_NAME'] = $member['loginname'];
			$_SESSION['SESS_DESIGN'] = $member['design'];
			$_SESSION['SESS_DEPT'] = $member['dept'];
			$_SESSION['SESS_FNY'] =$fny;
			$_SESSION['SESS_CMPC'] =$cmpc;
			$_SESSION['SESS_CMP'] =$cmp;
			$_SESSION['SESS_CMPADD1'] =$cmpadd1;
			$_SESSION['SESS_CMPADD1_1'] =$cmpadd1_1;
			$_SESSION['SESS_CMPADD2'] =$cmpadd2;
			$_SESSION['SESS_CMPADD2_1'] =$cmpadd2_1;
			$_SESSION['SESS_HELPLINE']=$helpline_no;
			$_SESSION['SESS_PAN']=$pan_no;
			$_SESSION['SESS_SERTAX']=$sertax_no;
			$_SESSION['SESS_SMSUSER']=$smsuser_no;
			$_SESSION['SESS_SMSPWD']=$smspwd_no;
			$_SESSION['SESS_SMSSID']=$smssid_no;
			$_SESSION['SESS_DSDET']=$ds_details;
			$_SESSION['SESS_PREPRINT']=$pre_printed;
			$_SESSION['SESS_SHOWLOGO']=$show_logo;
			$_SESSION['SESS_MAILFROM']=$mail_from;
			$_SESSION['SESS_MAILTO']=$mail_to;
			$_SESSION['SESS_DBCONPATH']=$rootpath."db_connect.php";
			$_SESSION['SESS_SIDEMENUPATH']=$rootpath."header.php";
			$_SESSION['SESS_HEADERPATH']=$rootpath."side_menu.php";
			$_SESSION['SESS_BRANCH']='HO';
			$_SESSION['SESS_STATUSARR']=array("10"=>"CUTTING","20"=>"STICHING","30"=>"QUALITY CHECK","40"=>"WASHING","50"=>"PRINTING","60"=>"EMBROIDERY","70"=>"FINISHING");
			
			
			//code to fetch product details for dispaly and save in session
			$sql = "SELECT * FROM  `master` where mstype = 'PCD' ORDER BY  `code` ASC ";
			$result = mysqli_query($con,$sql);
			while($row = mysqli_fetch_array($result))
			{
			$_SESSION['SESS_PCD'][$row['desc']] = $row['det']; 
			}

			
			session_write_close();
			echo "bingo";
			//header("location: bookinghome.php");
			exit();
		}else {
			//Login failed
			echo "whack";
			//header("location: login_failed.html");
			exit();
		}
	}else {
		die("Query failed");
	}
?>