<?php

include "../smtp.php";
include"initialize_page.php";
include"systemfunctions.php";
//include"sms_function.php";
require "../twilio_sms.php";

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

include realpath("../").'/vendor/autoload.php';

use Mpdf\Mpdf;


       if(isset($_POST['q'])&&$_POST['q']!="")
          {
			  $q=$_POST['q'];
			  
			  switch($q)
			      {
					
					  case "register_new_user":
					    {

					
							$u_userid=mysqli_real_escape_string($con,trim($_POST['uuserid']));
							$u_firstname=mysqli_real_escape_string($con,trim($_POST['ufname']));
							$u_lastname=mysqli_real_escape_string($con,trim($_POST['ulastname']));
							$u_password=mysqli_real_escape_string($con,trim($_POST['upassword']));
							$u_confirmpassword=mysqli_real_escape_string($con,trim($_POST['confirmpassword']));
							$u_emailid=mysqli_real_escape_string($con,trim($_POST['emailid']));
							$u_phonenumber=mysqli_real_escape_string($con,trim($_POST['phonenumber']));
							$u_dateofbirth=mysqli_real_escape_string($con,trim($_POST['dateofbirth']));
							$u_gender=mysqli_real_escape_string($con,trim($_POST['ugender']));
							$u_address=mysqli_real_escape_string($con,trim($_POST['uaddress']));
							$u_cityname=mysqli_real_escape_string($con,trim($_POST['ucityname']));
							$u_state=mysqli_real_escape_string($con,trim($_POST['ustate']));
							$u_zipcode=mysqli_real_escape_string($con,trim($_POST['zipcode']));
							$u_accounttype=mysqli_real_escape_string($con,trim($_POST['uaccounttype']));
							$u_accountpin=mysqli_real_escape_string($con,trim($_POST['accpin']));
							$u_verifyaccountpin=mysqli_real_escape_string($con,trim($_POST['conaccpin']));
							$var_img=$_FILES["file"]["name"];
							               //test for empty
										     
											              if(($u_userid=="")||($u_firstname=="")||($u_lastname=="")||($u_password=="")||($u_confirmpassword=="")||($u_emailid=="")||($u_phonenumber=="")||($u_dateofbirth=="")||($u_gender=="")||($u_address=="")||($u_cityname=="")||($u_state=="")||($u_zipcode=="")||($u_accounttype=="")||($u_accountpin=="")||($u_verifyaccountpin=="")||($var_img==""))
											   {
												 echo "empty";  
											   }
											   else
											    {
												      //test password and confirm password
													    if($u_password==$u_confirmpassword)
														  {
															    if($u_accountpin==$u_verifyaccountpin)
																  {
																	  //test username valid or not
																	    $check_username=username_validation($u_userid,'3','50');
																	     if($check_username=="valid")
																		   {
																			   //test username existing
																			   
																		$test_usernameavaibality=bankcustomer_test($u_userid,'x_userid');
																		         if($test_usernameavaibality==0)
																				 {
																				    //test email
																					$test_emailav=bankcustomer_test($u_emailid,'x_email');
																					   if($test_emailav==0)
																					     {
																							 
																						 $my_filename = $_FILES["file"]["name"];
											$my_filesize=$_FILES["file"]["size"];
											$my_filetype=$_FILES["file"]["type"];
											$my_fileerror=$_FILES["file"]["error"];
											 $my_filetempname=$_FILES["file"]["tmp_name"];
										    $my_filepath="../user/pics/";
											
						$gg_filef=mafiaphotauploader($my_filename, $my_filetype, $my_filesize, $my_fileerror, $my_filetempname, $my_filepath);
						             if(($gg_filef=="wrongfile")||($gg_filef=="errorfile"))        
						                 {
											  if($gg_filef=="wrongfile") 
											  {
												echo 'wrongfile';  
											  }
											  else
											  {
												echo 'errorfile';  
											  }
										 }
										 else
										 {
											 $currency_id = website_settingdata("x_currencysimbol");
											 $time_time = time();
											  mysqli_query($con,"INSERT into x_users SET x_userid='$u_userid', x_fname='$u_firstname', x_lname='$u_lastname', x_password='$u_password', x_email='$u_emailid', x_phonenumber='$u_phonenumber', x_dob='$u_dateofbirth', x_pic='$gg_filef', x_gender='$u_gender', x_address='$u_address', x_city='$u_cityname', x_state='$u_state', x_zip='$u_zipcode', x_acpin='$u_accountpin',x_status='N'");
											  $last_id = mysqli_insert_id($con);
											 
											  mysqli_query($con,"INSERT into x_anotheracc SET x_actype='$u_accounttype', x_status='N', x_time='$time_time', x_totalbalance='0',x_for_main='main_account',x_userid='$last_id',x_currencyid='$currency_id'");
											
											 //send email
											 $u_namex=$u_firstname." ".$u_lastname;
											 $msg_template=email_templateregister($u_namex);
											 $admin_webmail=website_settingdata("x_webmail");
														$to =$u_emailid;
$subject = " Your account has been created";

$message = $msg_template;

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <'.$admin_webmail.'>' . "\r\n";


//mail($to,$subject,$message,$headers);
sendMailSmtp($to,$subject,$message,$admin_webmail);

      $sms_text='Dear '.$u_firstname.' your account have been created successfully. Your account number will be generated soon. enquiry call '.website_settingdata("x_contactnumber");
										sendsms($u_phonenumber,$sms_text);	 
											 echo "done";
											 
										 }	 
																						 }
																						 else
																						 {
																						echo "emialalready";	 
																						 }
																					 
																				 }
																				 else
																				 {
																				echo "usernamealreadyexist";	 
																				 }
																		   }
																		   else
																		   {
																			   
																			echo "usernamenotvalid";   
																		   }
																  }
																  else
																  {
																	echo "pinnotmatch";  
																  }
															  
														  }
														  else
														  {
															  
															echo "passnotmatch";  
														  }
													  	
													
												}
							     
							
						  break;	
						}
						
		case "add_new_account":
		{
				
			$user_id = $_POST['id_user'];
			$u_another_accounttype=$_POST['uaccounttype'];
		    $currency_id = $_POST['currency_id'];
			
			
			if($u_another_accounttype == '' || $currency_id == '')
			{
				echo "empty";
			}
			else{
				
				$time_time = time();
				
				 //echo $sql = "INSERT into x_anotheracc SET x_userid='$user_id',x_currencyid='$currency_id',x_actype='$u_another_accounttype',x_status='N',x_totalbalance='0',x_time='$time_time'";
				
	            mysqli_query($con,"INSERT into x_anotheracc SET x_userid='$user_id',x_currencyid='$currency_id',x_actype='$u_another_accounttype',x_status='N',x_totalbalance='0',x_time='$time_time'");
					
					
				$user_data=mysqli_query($con,"SELECT * FROM x_users WHERE x_id ='$user_id'");
				
			    $user_array=mysqli_fetch_array($user_data);
				$user_fname=$user_array['x_fname'];
		        $user_lname=$user_array['x_lname'];
		        $user_emailid=$user_array['x_email']; 
		        $user_phonenumber=$user_array['x_phonenumber'];								 //send email
				$u_namex=$user_fname." ".$user_lname;
																  $msg_template=email_templateregister($u_namex);
															      $admin_webmail=website_settingdata("x_webmail");
																  $to =$user_emailid;
			   $subject = " Your account has been created";

			   $message = $msg_template;

				// Always set content-type when sending HTML email
				$headers = "MIME-Version: 1.0" . "\r\n";
				$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

				// More headers
				$headers .= 'From: <'.$admin_webmail.'>' . "\r\n";


				//mail($to,$subject,$message,$headers);
				sendMailSmtp($to,$subject,$message,$admin_webmail);
				
				$sms_text='Dear '.$user_fname.' your '.$u_another_accounttype.' account have been created successfully. Your account number will be generated soon. enquiry call '.website_settingdata("x_contactnumber");
														           sendsms($user_phonenumber,$sms_text);	 
															echo "done";
											
				
		
			}
			
				
			break;	
		}
					     case "user_account_action":
						     {
								 $id=$_POST['id'];
								 $action=$_POST['action'];
								 $accid = $_POST['accid'];
								 
								 mysqli_query($con,"UPDATE x_anotheracc SET x_status='$action' WHERE x_id='$accid'");
								    if($action=="Y")
									  {
										//send email
										
										$u_namex=user_bankuser($id,"x_fname")." ".user_bankuser($id,"x_lname");
										$u_acnumber=user_bankuser($accid,"x_time");
										$msg_template=activated_mailertem($u_namex,$u_acnumber);  
										  $u_phonenumber=user_bankuser($id,"x_phonenumber");
										   $admin_webmail=website_settingdata("x_webmail");
														$to =user_bankuser($id,"x_email");
$subject = "Your account has been activated";

$message = $msg_template;

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <'.$admin_webmail.'>' . "\r\n";


//mail($to,$subject,$message,$headers);
sendMailSmtp($to,$subject,$message,$admin_webmail);

     $sms_text='Dear '.$u_namex.' your account have been created successfully. Your account number is '.$u_acnumber.' . Enquiries call '.website_settingdata("x_contactnumber");
										sendsms($u_phonenumber,$sms_text);	
										echo "done";
									  }
							   break;	 
							 }
							 
							 case "user_action":
						     {
								  $id=$_POST['id'];
								  $action=$_POST['action'];
								 
								 
								 mysqli_query($con,"UPDATE x_users SET x_status='$action' WHERE x_id='$id'");
								    echo "done";
							   break;	 
							 }
							 
							 
							 
							case "user_password_change":
						   {
							   $id=$_POST['id'];
							 $password=$_POST['password'];
							 $pin=$_POST['pin'];
							 
							 mysqli_query($con,"UPDATE x_users SET x_password='$password',x_acpin='$pin' WHERE x_id='$id'");
							break;   
						   }
							 case "delete_user":
							   {
								   $id=$_POST['id'];
								 $action="D";
								 
								 mysqli_query($con,"DELETE FROM x_users  WHERE x_id='$id'"); 
								break;   
							   }
							   case "delete_statement":
							   {
							   		$id=$_POST['id'];
								 
								 mysqli_query($con,"DELETE FROM x_statement  WHERE x_id='$id'"); 
								break; 
							   }
							   case "edit_this_emailid":
							     {
									$id=$_POST['id'];
									$new_email=mysqli_real_escape_string($con,trim($_POST['myemailnew'])); 
									  if($new_email=="")
									   {
										echo "empty";   
										   
									   }
									   else
									   {
										   //test for email
										   
										   $result_mail= master_emailtest($id,$new_email);
										     if($result_mail==0)
											   {
												
												mysqli_query($con,"UPDATE x_users SET x_email='$new_email' WHERE x_id='$id'");
												echo "done";   
											   }
											   else
											   {
											   echo "emialalready";
											   }
									   }
									 
								break;	 
								 }
			 case "make_transaction_user":
				{
					$accid = $_POST['accid'];
					$id = $_POST['userid'];
					$currencyid = $_POST['currencyid'];
					
					$transaction_type=mysqli_real_escape_string($con,trim($_POST['transictiontype']));
					$amount_tr = mysqli_real_escape_string($con,trim($_POST['amountuser']));
					$date_transfer=mysqli_real_escape_string($con,trim($_POST['dateoftransfer']));
					$description_tr=mysqli_real_escape_string($con,trim($_POST['trdescription']));
					
					
						if(($transaction_type=="")||($amount_tr=="")||($date_transfer=="")||($description_tr==""))
						  {
							  if($transaction_type=="")
							   {
								echo "select";   
							   }
							   else
							   {
								 echo "empty";
							   }
							  
						  }
						  else
						  {
							   $test_amount = numeric_value_test($amount_tr);
								 if($test_amount == "valid")
								   {
									//credit amoiunt
									//fetch total balance
									$total_balance = user_bankuser($accid,"x_totalbalance");
									$test_userstatusss = user_bankuser($accid,"x_status");
									
									   if($transaction_type=="credit")
										 {
											if($test_userstatusss=="Y")
											 {
										mysqli_query($con,"INSERT into x_statement SET x_userid='$id', x_amount='$amount_tr', x_type='$transaction_type', x_trdate='$date_transfer', x_description='$description_tr', x_fee='0', x_status='Y',x_acountid='$accid'");
										//now total 
										$now_totalbalance=$total_balance+$amount_tr;
										mysqli_query($con,"UPDATE x_anotheracc SET x_totalbalance='$now_totalbalance' WHERE x_id='$accid'");
										
										//$sql ="SELECT * FROM x_statement WHERE x_acountid='$accid' and x_userid='$id' and x_amount='$amount_tr' and x_type='$transaction_type' and x_trdate='$date_transfer' and x_description='$description_tr' and x_fee='0' and x_status='Y' ORDER by x_id DESC";
										
										$ref_q=mysqli_query($con,"SELECT * FROM x_statement WHERE x_acountid='$accid' and x_userid='$id' and x_amount='$amount_tr' and x_type='$transaction_type' and x_trdate='$date_transfer' and x_description='$description_tr' and x_fee='0' and x_status='Y' ORDER by x_id DESC");
										$ref_array=mysqli_fetch_array($ref_q);
										 $ref_number=$ref_array['x_id'];
										
										//send mail to user
										$email_userbalance=user_bankuser($accid,"x_totalbalance");
										
										$e_username=user_bankuser($id,"x_fname").' '.user_bankuser($id,"x_lname");
										$e_useraccount=user_bankuser($accid,"x_time");
										$e_email=user_bankuser($id,"x_email");
										$u_phonenumber=user_bankuser($id,"x_phonenumber");
										
										$email_userbalance =  number_format($email_userbalance,2);
										$amount_tr = number_format($amount_tr,2);
										
										
										
										
										
										$mailer_template=mailer_debitcredittempl($e_useraccount,$e_username,$description_tr,$ref_number,$email_userbalance,$amount_tr,$transaction_type,$currencyid);
										
										$admin_webmail=website_settingdata("x_webmail");
										 $to =$e_email;
$subject = "Transaction Notification Mail ";

$message = $mailer_template;

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <'.$admin_webmail.'>' . "\r\n";


//mail($to,$subject,$message,$headers);
sendMailSmtp($to,$subject,$message,$admin_webmail);

$tttx=date("l jS \of F Y h:i:s A");
$sms_text="Credit Alert, Acc: ".$e_useraccount.", Amt:".$amount_tr.", Desc:". $description_tr.",  Time:".$tttx." , Avail Bal:".$email_userbalance;
//sendsms($u_phonenumber,$sms_text);

sendMessage($u_phonenumber,$sms_text);
									
										echo "done";
											 }
											 else
											 {
												 echo "inactiveuser";
												 
											 }
										
										 }
										 else
										 {
										   //test condition for debit
											
											if($amount_tr <= $total_balance)
											   {
											   if($test_userstatusss=="Y")
											 {
												mysqli_query($con,"INSERT into x_statement SET x_userid='$id', x_amount='$amount_tr', x_type='$transaction_type', x_trdate='$date_transfer', x_description='$description_tr', x_fee='0', x_status='Y',x_acountid='$accid'");
												
												
										$ref_q=mysqli_query($con,"SELECT * FROM x_statement WHERE x_acountid='$accid,'x_userid='$id' and x_amount='$amount_tr' and x_type='$transaction_type' and x_trdate='$date_transfer' and x_description='$description_tr' and x_fee='0' and x_status='Y' ORDER by x_id DESC");
										$ref_array=mysqli_fetch_array($ref_q);
										$ref_number=$ref_array['x_id'];
										//now total 
										$now_totalbalance = $total_balance-$amount_tr;
										mysqli_query($con,"UPDATE x_anotheracc SET x_totalbalance='$now_totalbalance' WHERE x_id='$accid'");
										
//send mail to user
										$email_userbalance = user_bankuser($accid,"x_totalbalance");
										
										$e_username=user_bankuser($id,"x_fname").' '.user_bankuser($id,"x_lname");
										$e_useraccount=user_bankuser($accid,"x_time");
										$e_email=user_bankuser($id,"x_email");
										$u_phonenumber=user_bankuser($id,"x_phonenumber");
										
										
										$email_userbalance = number_format($email_userbalance,2);
										$amount_tr = number_format($amount_tr,2);
										
										// ****changes*****
										$currencyid = $_POST['currencyid'];
										
										$mailer_template=mailer_debitcredittempl($e_useraccount,$e_username,$description_tr,$ref_number,$email_userbalance,$amount_tr,$transaction_type,$currencyid);
										
										$admin_webmail=website_settingdata("x_webmail");
									$to =$e_email;
$subject = "Transaction Notification Mail ";

$message = $mailer_template;

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <'.$admin_webmail.'>' . "\r\n";


//mail($to,$subject,$message,$headers);
sendMailSmtp($to,$subject,$message,$admin_webmail);

						  $tttx=date("l jS \of F Y h:i:s A");
// $sms_text='Debit Alert,
// Acc: '.$e_useraccount.'
// Amt:'.$amount_tr.'
// Desc: '.$description_tr.' 
// Time:'.$tttx.'
// Avail Bal:'.$email_userbalance;			 
						 

$sms_text="Debit Alert, Acc: ".$e_useraccount.", Amt:".$amount_tr.", Desc:". $description_tr.",  Time:".$tttx." , Avail Bal:".$email_userbalance;

//sendsms($u_phonenumber,$sms_text);
sendMessage($u_phonenumber,$sms_text);
										
										echo "done"; 
											 }
											 else
											 {
												 
												 echo "inactiveuser";
											 }
												   
											   } 	
											   else
											   {
												echo "insufficientfund";   
											   }
											
											 
										 }
									   
								   }
								   else
								   {
									echo "amountnotvalid";   
								   }
							  
						  }
					
					break;
				}
									case "add_new_creditcard":
									  {
										  $user_id=$_POST['user_id'];
										  $acc_id=$_POST['acc_id'];
										  $credit_cardnumber=mysqli_real_escape_string($con,trim($_POST['ccnumber']));
										  $name_oncard=mysqli_real_escape_string($con,trim($_POST['nameoncard']));
										    if(isset($_POST['cardtype']))
											  {
											 $card_type=$_POST['cardtype'];	  
											  }
											  else
											  {
												$card_type="";  
											  }
										 
										  $cvv_card=mysqli_real_escape_string($con,trim($_POST['cvvc']));
										  $mounth_ex=mysqli_real_escape_string($con,trim($_POST['exmounth']));
										  $year_ex=mysqli_real_escape_string($con,trim($_POST['exyear']));
										  $w_limit=mysqli_real_escape_string($con,trim($_POST['wlimit']));
										     if(($credit_cardnumber=="")||($name_oncard=="")||($card_type=="")||($cvv_card=="")||($w_limit==""))
											   {
												   if($card_type=="")
												     {
														 echo "select";
													 }
													 else
													 {
													echo "empty";	 
													 }
											   }
											   else
											   {
												  $limit_test=numeric_value_test($w_limit);
												    if($limit_test=="valid")
													  {
														
													
														
														  mysqli_query($con,"INSERT into x_creditcards SET x_userid='$user_id',x_accountid='$acc_id', x_cardnumber='$credit_cardnumber', x_cardname='$name_oncard', x_cvv='$cvv_card', x_expirymounth='$mounth_ex', x_expiryyear='$year_ex', x_limit='$w_limit', x_type='$card_type', x_status='N'");
														  
														  echo "done";
													  }
													  else
													  {
														echo "notnumeric";  
													  }
											   }
										  
										break;  
									  }
									  case "edit_creditcard_details":
									   {
											  $id=$_POST['id'];
										  $credit_cardnumber=mysqli_real_escape_string($con,trim($_POST['ccnumber']));
										  $name_oncard=mysqli_real_escape_string($con,trim($_POST['nameoncard']));
										    if(isset($_POST['cardtype']))
											  {
											 $card_type=$_POST['cardtype'];	  
											  }
											  else
											  {
												$card_type="";  
											  }
										 
										  $cvv_card=mysqli_real_escape_string($con,trim($_POST['cvvc']));
										  $mounth_ex=mysqli_real_escape_string($con,trim($_POST['exmounth']));
										  $year_ex=mysqli_real_escape_string($con,trim($_POST['exyear']));
										  $w_limit=mysqli_real_escape_string($con,trim($_POST['wlimit']));
										  $status_card=$_POST['cardstatus'];
										     if(($credit_cardnumber=="")||($name_oncard=="")||($status_card=="no")||($cvv_card=="")||($w_limit==""))
											   {
												   if($status_card=="no")
												     {
														 echo "select";
													 }
													 else
													 {
													echo "empty";	 
													 }
											   }
											   else
											   {
												  $limit_test=numeric_value_test($w_limit);
												    if($limit_test=="valid")
													  {
														  mysqli_query($con,"UPDATE x_creditcards SET  x_cardnumber='$credit_cardnumber', x_cardname='$name_oncard', x_cvv='$cvv_card', x_expirymounth='$mounth_ex', x_expiryyear='$year_ex', x_limit='$w_limit', x_type='$card_type', x_status='$status_card' WHERE x_id='$id'");
														  
														  echo "done";
													  }
													  else
													  {
														echo "notnumeric";  
													  }
											   }
										  
										break;    
										   
									   }
									   case "add_new_slider":
									     {
											 
											$s_text=mysqli_real_escape_string($con,trim($_POST['ad_text']));
											$s_heading=mysqli_real_escape_string($con,trim($_POST['ad_head']));
											$s_img=$_FILES["file"]["name"];
											  if(($s_text=="")||($s_heading=="")||($s_img==""))
											    {
												echo "empty";	
												}
												else
												{
													  //get functions varibales
										    $my_filename=$_FILES["file"]["name"];
											$my_filesize=$_FILES["file"]["size"];
											$my_filetype=$_FILES["file"]["type"];
											$my_fileerror=$_FILES["file"]["error"];
											 $my_filetempname=$_FILES["file"]["tmp_name"];
										    $my_filepath="../images/";
											
						$gg_filef=mafiaphotauploader($my_filename, $my_filetype, $my_filesize, $my_fileerror, $my_filetempname, $my_filepath);
						             if(($gg_filef=="wrongfile")||($gg_filef=="errorfile"))        
						                 {
											  if($gg_filef=="wrongfile") 
											  {
												echo 'wrongfile';  
											  }
											  else
											  {
												echo 'errorfile';  
											  }
										 }
										 else
										 {
											//update data with image
											 mysqli_query($con,"INSERT into x_slider SET x_text='$s_text', x_heading='$s_heading', x_image='$gg_filef'");
										      echo 'done';  
											 
										 }
												}
											 
										break;	 
										 }
										  case "add_new_slider1":
									     {
											 
										
											$s_heading=mysqli_real_escape_string($con,trim($_POST['ad_head']));
											$s_img=$_FILES["file"]["name"];
											  if(($s_heading=="")||($s_img==""))
											    {
												echo "empty";	
												}
												else
												{
													  //get functions varibales
										    $my_filename=$_FILES["file"]["name"];
											$my_filesize=$_FILES["file"]["size"];
											$my_filetype=$_FILES["file"]["type"];
											$my_fileerror=$_FILES["file"]["error"];
											 $my_filetempname=$_FILES["file"]["tmp_name"];
										    $my_filepath="../images/";
											
						$gg_filef=mafiaphotauploader($my_filename, $my_filetype, $my_filesize, $my_fileerror, $my_filetempname, $my_filepath);
						             if(($gg_filef=="wrongfile")||($gg_filef=="errorfile"))        
						                 {
											  if($gg_filef=="wrongfile") 
											  {
												echo 'wrongfile';  
											  }
											  else
											  {
												echo 'errorfile';  
											  }
										 }
										 else
										 {
											//update data with image
											 mysqli_query($con,"INSERT into x_slider1 SET  x_heading='$s_heading', x_image='$gg_filef'");
										      echo 'done';  
											 
										 }
												}
											 
										break;	 
										 }
										 case "delete_slider":
										 {
											 $id=$_POST['id'];
										
										mysqli_query($con,"DELETE FROM x_slider WHERE x_id='$id'");
										break;	 
										 }
										  case "delete_slider1":
										 {
											 $id=$_POST['id'];
										
										mysqli_query($con,"DELETE FROM x_slider1 WHERE x_id='$id'");
										break;	 
										 }
										 case "send_ondemandcode":
										 {
										  $action_code=$_POST['action'];
										  $id=$_POST['id'];	
										  $code_gen=$action_code.rand(111111,999999);
										  if($action_code!="")
										    {
										mysqli_query($con,"INSERT into x_code SET x_userid='$id', x_code='$code_gen', x_type='$action_code'");
										
										//send mail
										
										$my_name=user_bankuser($id,'x_fname')." ".user_details($id,'x_lname');;
														$msg_template=otp_firsttemplate($code_gen,$my_name,$action_code);
														$my_mail=user_bankuser($id,'x_email');
														$admin_webmail=website_settingdata("x_webmail");
														$to =$my_mail;
$subject = $action_code." Code";

$message = $msg_template;

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <'.$admin_webmail.'>' . "\r\n";


//mail($to,$subject,$message,$headers);
sendMailSmtp($to,$subject,$message,$admin_webmail);

											}
											 
										break;	 
										 }
										 case "update_website_setting":
										 {
											 $website_name=mysqli_real_escape_string($con,trim($_POST['wname']));
											 $website_url=mysqli_real_escape_string($con,trim($_POST['wurl']));
											 $currency_symbol=mysqli_real_escape_string($con,trim($_POST['csymbol']));
											 $xsxwxixfxtxcode=mysqli_real_escape_string($con,trim($_POST['cxsxwxixfxtxcode']));
											 $web_mail=mysqli_real_escape_string($con,trim($_POST['wemail']));
											 $q_mail=mysqli_real_escape_string($con,trim($_POST['qmaill']));
											 $bank_name=mysqli_real_escape_string($con,trim($_POST['cbankname']));
											 $bank_qmail=mysqli_real_escape_string($con,trim($_POST['bqueryemail']));
											 $bank_branch=mysqli_real_escape_string($con,trim($_POST['userbranch']));
											 $allowresumetransfer=mysqli_real_escape_string($con,trim($_POST['allowresumetransfer']));
$bank_contactno=mysqli_real_escape_string($con,trim($_POST['bcontactno']));
                                  $bank_sitetitle=mysqli_real_escape_string($con,trim($_POST['webtitlell']));
								$login_type=mysqli_real_escape_string($con,trim($_POST['logintype']));
								$noofstepinfundtransfer=mysqli_real_escape_string($con,trim($_POST['noofstepinfundtransfer']));
											 mysqli_query($con,"UPDATE x_websitesetting SET x_websitename='$website_name', x_weburl='$website_url', x_webmail='$web_mail', x_qmail='$q_mail', x_currencysimbol='$currency_symbol', x_bankname='$bank_name', x_xsxwxixfxtxcode='$xsxwxixfxtxcode', x_bankcontactemail='$bank_qmail', x_branch='$bank_branch', x_contactnumber='$bank_contactno', x_titleweb='$bank_sitetitle', x_logintype='$login_type',noofstepinfundtransfer='$noofstepinfundtransfer',allowresumetransfer='$allowresumetransfer' WHERE x_id='1'");
											 
											 echo "done";
											 
											 break;
										 }
										 case "cancel_transaction_byadmin":
										 {
										$id=$_POST['id'];
										
										mysqli_query($con,"UPDATE x_fundtransfer SET x_step='CA' WHERE x_id='$id'");	 
										break;	 
										 }
										
				case "approve_incommiung_fundtransfer":
				 {
					 $id = $_POST['id']; 
					
					 $test_q=mysqli_query($con,"SELECT * FROM x_fundtransfer WHERE x_id='$id'");
					 $test_row=mysqli_num_rows($test_q);
						if($test_row!=0)
						  {
							 $test_array=mysqli_fetch_array($test_q);
							 $test_type=$test_array['x_trtype'];
								
							
							 $test_acnumber =$test_array['x_receiveraccountnu'];   
						     $test_userid = $test_array['x_userid'];
							 $test_accountid = $test_array['x_accountid'];
							
							 $core_amount = $test_array['x_amount'];
							 $x_description = $test_array['x_description'];
							 
							 $core_fee=$test_array['x_fee'];
							 $test_date=$test_array['x_trdate'];
							 $x_id=$test_array['x_id'];
							 
							  //get user amount
							  $test_recieverusername = $test_array['x_receivername'];
							  
							  $balance_user = user_bankuser ($test_accountid,"x_totalbalance");
							  
							 $u_currencyid = user_bankuser($test_accountid,"x_currencyid");
										
							 $u_currency = currency_data("x_currencysymbol",$u_currencyid);
										 									
							 $user_currency_val = currency_data("x_currencyvalue",$u_currencyid); 
							 
							 $recievre_userido=findtimetouserid($test_acnumber);
							   $recievre_accido = findtimetoaccountid($test_acnumber);
							   
							 $rec_curencyid = user_bankuser($recievre_accido,"x_currencyid");
										 
							 $rec_currency_val = currency_data("x_currencyvalue",$rec_curencyid);
										
							 $rec_currency = currency_data("x_currencysymbol",$rec_curencyid);
							 
									 
							$converted_amount =  currencyConverter( $rec_currency_val,$user_currency_val,$core_amount);
							
							
										 
							$converted_amount_replacecomma =str_replace(",","",$converted_amount); 
							
							
							
							 $test_amount = $converted_amount_replacecomma + $core_fee; 
							
							  if($balance_user < $test_amount)
								{
									
								 echo "lessamount";	
								}
								else
								{
								  if($test_type=="local")
								  {
								     $user_acinput=user_bankuser($test_accountid,"x_time");
									
									 $uuu_email=user_bankuser($test_userid,"x_email");
									 $u_phonenumber=user_bankuser($test_userid,"x_phonenumber");
									
							        // $bank_symbol=website_settingdata("x_currencysimbol");
									 
									 //find name of reciver account no
								      $receiver_username=findaccounttoname($test_acnumber);
									
								      //$recievre_userido=findtimetouserid($test_acnumber);

								 
								
								      $sender_name=user_bankuser($test_userid,"x_fname").' '.user_bankuser($test_userid,"x_lname");
									  
								       $receiver_balance=user_bankuser($recievre_accido,"x_totalbalance");
									   
									 
									   
										 $uuu_email1=user_bankuser($recievre_userido,"x_email");
										 
                                       
											
											
										   if($test_acnumber == $user_acinput)
											 {
											echo "notinownac";	 
											 }
											 else
											 {
							
								           //entry in statement
										  $core_amountcomma = number_format($core_amount,2);
										  
										 
										
										 
										  
										  
										  $debit_description='Fund transfer of '.$u_currency.' '.$converted_amount."+".$core_fee.' to '.$receiver_username.' Account '.$test_acnumber;
												 
										  $credit_description='Fund transfer of '.$rec_currency.' '.$core_amountcomma.' from '.$sender_name.' Account '.$user_acinput;
												
											
										mysqli_query($con,"INSERT into x_statement SET x_id='$x_id',x_amount='$converted_amount_replacecomma', x_userid='$test_userid', x_type='debit', x_trdate='$test_date', x_description='$debit_description', x_fee='$core_fee', x_status='Y',x_acountid='$test_accountid'");
												 echo "INSERT into x_statement SET x_amount='$converted_amount_replacecomma', x_userid='$test_userid', x_type='debit', x_trdate='$test_date', x_description='$debit_description', x_fee='$core_fee', x_status='Y',x_acountid='$test_accountid'";
												 
												 //deduct from sender user and update 
								     	//i resume here
                             				//used x_description instead of debit_description for user description in statement in both query			
							         $rdx_q=mysqli_query($con,"SELECT * FROM x_statement WHERE x_amount='$converted_amount_replacecomma' and x_userid='$test_userid' and x_type='debit' and x_trdate='$test_date' and x_description='$x_description' and x_fee='$core_fee' and x_status='Y' ORDER by x_id DESC");
									 $rdx_array=mysqli_fetch_array($rdx_q);
												  $rdx_mainid=$rdx_array['x_id'];
												
									 mysqli_query($con,"INSERT into x_statement SET x_id='$x_id',x_amount='$core_amount', x_userid='$recievre_userido', x_type='credit', x_trdate='$test_date', x_description='$credit_description', x_status='Y', x_fee='',x_acountid='$recievre_accido'");			 
												 
												/* echo "INSERT into x_statement SET x_amount='$core_amount', x_userid='$recievre_userido', x_type='credit', x_trdate='$test_date', x_description='$x_description', x_status='Y', x_fee='',x_acountid='$recievre_accido'";
												 die("error");*/
									$debit_userbalance=$balance_user-$test_amount;
												
								    $credit_userbalance=$receiver_balance+$core_amount;
												 
												 
												 //update debit
								
				                  mysqli_query($con,"UPDATE x_anotheracc SET x_totalbalance='$debit_userbalance' WHERE x_id='$test_accountid'");
												 
		                          mysqli_query($con,"UPDATE x_anotheracc SET x_totalbalance='$credit_userbalance' WHERE x_id='$recievre_accido'");
												 
											 
								  mysqli_query($con,"UPDATE x_fundtransfer SET x_step='CF' WHERE x_id='$id'");
												 
												 
								 $debit_userbalancecomma = number_format($debit_userbalance,2);
								 $credit_userbalancecomma = number_format($credit_userbalance,2);
								 $test_amountcomma = number_format($test_amount,2);
								 
								 //enetre to next user
								 $de_mailertemplate=mailer_debitcredittempl($user_acinput,$sender_name,$debit_description,$rdx_mainid,$debit_userbalancecomma,$test_amountcomma,'debit',$u_currencyid);
												 
												 //send mails to relivant users
												 
								 $admin_webmail=website_settingdata("x_webmail");
								$to =$uuu_email;
$subject = "Debit Amount Notification";

$message = $de_mailertemplate;

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <'.$admin_webmail.'>' . "\r\n";


//mail($to,$subject,$message,$headers);
sendMailSmtp($to,$subject,$message,$admin_webmail);

   //mail to credit user
   
   $de_mailertemplate1=mailer_debitcredittempl($test_acnumber,$receiver_username,$credit_description,$rdx_mainid,$credit_userbalancecomma,$core_amountcomma,'credit',$rec_curencyid);
												 
												 //send mails to relivant users
												 
												
								$to1 =$uuu_email1;
$subject1 = "Credit Amount Notification";

$message1 = $de_mailertemplate1;

// Always set content-type when sending HTML email
$headers1 = "MIME-Version: 1.0" . "\r\n";
$headers1 .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers1 .= 'From: <'.$admin_webmail.'>' . "\r\n";


//mail($to1,$subject1,$message1,$headers1);
sendMailSmtp($to1,$subject1,$message1,$admin_webmail);
   
   //credit sms
   
   
   //debit sms
   
	 $tttx=date("l jS \of F Y h:i:s A");
$sms_text='Debit Alert
Acc: '.$user_acinput.'
Amt:'.$test_amountcomma.'
Desc: '.$debit_description.' 
Time:'.$tttx.'
Avail Bal:'.$debit_userbalancecomma;
					 
					 
					 sendsms($u_phonenumber,$sms_text);
   
												 
  $sms_text1='Credit Alert
Acc: '.$test_acnumber.'
Amt:'.$core_amountcomma.'
Desc: '.$credit_description.' 
Time:'.$tttx.'
Avail Bal:'.$credit_userbalancecomma;
					 
					 
					 sendsms($u_phonenumber1,$sms_text1);												 
												 echo "done";
												 
												 
											 }
									   }
									   else
									   {
										   
										//intsernation fund transfer
										  $bank_symbol=website_settingdata("x_currencysimbol");
										  
										  $user_acinput = user_bankuser($test_accountid,"x_time"); 
										  $sender_name=user_bankuser($test_userid,"x_fname").' '.user_bankuser($test_userid,"x_lname");
										  
                                          $uuu_email = user_bankuser($test_userid,"x_email"); 							  
										  $u_phonenumber=user_bankuser($test_userid,"x_phonenumber");
										  
										  
										  $core_amountcomma = number_format($core_amount,2);
									
										
									$u_currencyid = user_bankuser($test_accountid,"x_currencyid");
										
									 $u_currency = currency_data("x_currencysymbol",$u_currencyid);
										  
										
                                     $debit_description='Fund transfer of '.$u_currency.' '.$core_amountcomma."+".$core_fee.' to '.$test_recieverusername.' Account '.$test_acnumber;

										 $x_description = $test_array['x_description'];
										 //used x_description instead of debit_description for user description in statement
									mysqli_query($con,"INSERT into x_statement SET x_id='$x_id',x_amount='$core_amount', x_userid='$test_userid', x_type='debit', x_trdate='$test_date', x_description='$x_description', x_fee='$core_fee', x_status='Y',x_acountid='$test_accountid'");
										 
										$rdx_q=mysqli_query($con,"SELECT * FROM x_statement WHERE x_amount='$core_amount' and x_userid='$test_userid' and x_type='debit' and x_trdate='$test_date' and x_description='$debit_description' and x_fee='$core_fee' and x_status='Y' ORDER by x_id DESC");
										
										$rdx_array = mysqli_fetch_array($rdx_q);
										
										$rdx_mainid = $rdx_array['x_id'];
										
										$total_amount = $core_amount + $core_fee;
										
										$debit_userbalance=$balance_user-$total_amount;
										
										mysqli_query($con,"UPDATE x_anotheracc SET x_totalbalance='$debit_userbalance' WHERE x_id='$test_accountid'");
										
										mysqli_query($con,"UPDATE x_fundtransfer SET x_step='CF' WHERE x_id='$id'");
										 
										 //send email
										$debit_userbalancecomma = number_format($debit_userbalance,2);
										 
										  $de_mailertemplate=mailer_debitcredittempl($user_acinput,$sender_name,$debit_description,$rdx_mainid,$debit_userbalancecomma,$core_amountcomma,'debit',$u_currencyid);
												 
												 //send mails to relivant users
												 
												 $admin_webmail=website_settingdata("x_webmail");
												 
								$to =$uuu_email;
$subject = "Debit Amount Notification";

$message = $de_mailertemplate;

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <'.$admin_webmail.'>' . "\r\n";




/***
 * 
 * PREPARE PDF 
 * 
 * **/



 //send email with attachment
 $userQry = mysqli_query($con, "SELECT * FROM x_users where x_userid = '".$test_userid."' ");
 $getUserData = mysqli_fetch_array($userQry);
 
 // echo "<pre>";
 // print_r($getUserData);
 // print_r($_SESSION);
 
 include realpath("../").'/user/pdf-invoice.php';
 
 $html = attachTransaction($getUserData,$core_amountcomma,currency_data('x_currencysymbol', $u_currencyid),$debit_description,$user_acinput,$debit_userbalancecomma);
 
  

 $font_family = 'ayar';
 $fontDirs = [];
 $fontData = [];                
 $configMpdf = [
   'tempDir' => realpath("../").'/tempmpdf',
   'mode' => 'utf-8',
   'format' => [190, 236],
   'orientation' => 'P',
 
   'fontDir' => array_merge($fontDirs, [
	 realpath("../").  '/assets/fonts',
   ]),
   'fontdata' => $fontData + [
	   'ayar' => [
		 'R' => 'ayar.ttf',
		 'I' => 'ayar.ttf',
	 ]
   ],
   'default_font' => $font_family
 ];
 
 $filename = realpath("../").'/uploads/invoice.pdf';
 
 $mpdf = new Mpdf($configMpdf);
 $mpdf->WriteHTML( $html );
 ob_clean(); 
 //$mpdf->Output(realpath("../").'/tempmpdf/invoice.pdf','F');
 $mpdf->Output($filename,'F');


//mail($to,$subject,$message,$headers);
sendMailSmtp($to,$subject,$message,$admin_webmail,$filename);

$tttx=date("l jS \of F Y h:i:s A");
$sms_text='Debit Alert
Acc: '.$user_acinput.'
Amt:'.$core_amountcomma.'
Desc: '.$debit_description.' 
Time:'.$tttx.'
Avail Bal:'.$debit_userbalancecomma;
					 
					 
					 sendsms($u_phonenumber,$sms_text);
										 
										 
										 echo "done";  
									   }
									
								}
							  
						  }
				break;	 
				 }
										
										
										
										
										
										
										 case "send_msgtouser":
										 {
											 $id=$_POST['id'];
											 $msg_msg=mysqli_real_escape_string($con,trim($_POST['msgtrim']));
											   if($msg_msg=="")
											    {
												echo "empty";	
												}
												else
												{
													mysqli_query($con,"INSERT into x_chat SET x_userid='$id', x_by='admin', x_msg='$msg_msg', x_readstatus='U'");
													
													echo "done";
												}
											 
										break;	 
										 }
										 case "update_prpertyvalue":
										  {
											  $id=$_POST['id'];
											  $msg_msg=mysqli_real_escape_string($con,trim($_POST['msg']));
											    if($msg_msg=="")
												 {
												echo "empty";	 
												 }
												 else
												 {
													 mysqli_query($con,"UPDATE x_property SET x_value='$msg_msg' WHERE x_id='$id'");
													 echo "done";
												 }
											  
											break;  
										  }
										  case "edit_profile":
										  {
											  $admin_email=mysqli_real_escape_string($con,trim($_POST['pemail']));
											  $admin_password=mysqli_real_escape_string($con,trim($_POST['ppass']));
											  $admin_name=mysqli_real_escape_string($con,trim($_POST['pname']));
											  $admin_mobile=mysqli_real_escape_string($con,trim($_POST['pmob']));
											    
												mysqli_query($con,"UPDATE x_admin SET x_email='$admin_email', x_password='$admin_password', x_name='$admin_name', x_mobile='$admin_mobile' WHERE x_id='$user_id'");
											  echo "done";
											break;  
										  }
										  case "upload_fileimage":
										      {
										          $var_img=$_FILES["file"]["name"];
										          	
										          	if($var_img=="")
										          	{
										          	    echo "empty";
										          	}
										          	else
										          	{
										          	         $my_filename=$_FILES["file"]["name"];
											$my_filesize=$_FILES["file"]["size"];
											$my_filetype=$_FILES["file"]["type"];
											$my_fileerror=$_FILES["file"]["error"];
											 $my_filetempname=$_FILES["file"]["tmp_name"];
										    $my_filepath="../images/";
											
						$gg_filef=mafiaphotauploader($my_filename, $my_filetype, $my_filesize, $my_fileerror, $my_filetempname, $my_filepath);
						             if(($gg_filef=="wrongfile")||($gg_filef=="errorfile"))        
						                 {
											  if($gg_filef=="wrongfile") 
											  {
												echo 'wrongfile';  
											  }
											  else
											  {
												echo 'errorfile';  
											  }
										 }
										 else
										 {
											 mysqli_query($con,"UPDATE x_websitesetting SET x_logo='$gg_filef' WHERE x_id='1'");
											 echo "done";
											 
										 }
													}
										 break;  
									}
					
			case "add_new_currency" :
			{
				
			   
			      $currency_symbol=mysqli_real_escape_string($con,trim($_POST['currency_symbol']));
			   
			      $currency_value=strtoupper(mysqli_real_escape_string($con,trim($_POST['currency_value'])));
			
				if($currency_symbol!="" && $currency_value!=""){
			  
			
				mysqli_query($con, "INSERT INTO x_currency (x_currencysymbol,x_currencyvalue)VALUES('$currency_symbol','$currency_value')");
			      echo "done";
				}
				else{
					echo "empty";
				}
			break;  
			
		   }
		   case "edit_currency":
			{
			    $currency_symbol=mysqli_real_escape_string($con,trim($_POST['currency_symbol']));
			   
			    $currency_value=strtoupper(mysqli_real_escape_string($con,trim($_POST['currency_value'])));
				$id = $_POST['id'];
			
				if($currency_symbol!="" && $currency_value!=""){
			
			
				mysqli_query($con, "UPDATE x_currency SET  x_currencysymbol='$currency_symbol', x_currencyvalue='$currency_value' WHERE x_id='$id'");
			      echo "done";
				}
				else{
					echo "empty";
				}
			break;  
			
		   }
		   case "delete_currency":
			 {
				
			   
			    $id = $_POST['id'];
				
				mysqli_query($con,"DELETE FROM x_currency WHERE x_id='$id'");
				
			
			    break;  
		     }	
					  
		    case "add_loan_type":
			{
			      $loan_type=mysqli_real_escape_string($con,trim($_POST['loan_type']));
			   
			      $loan_interest=mysqli_real_escape_string($con,trim($_POST['loan_interest']));
			
				if($loan_type!="" && $loan_interest!="")
				{
			  
			      if(is_numeric($loan_interest))
				  {
				       mysqli_query($con,"INSERT INTO x_loantype (x_loan,x_loaninterest)VALUES('$loan_type','$loan_interest')");
					   
			            echo "done";
				  }
				  else
				  {
					  echo "notnumeric";
				  }
				}
				else{
					echo "empty";
				}
			break;  
		   }

            case "delete_loan_type":
			 {
				
			  
			    $id = $_POST['id'];
				
				mysqli_query($con,"DELETE FROM x_loantype WHERE x_id='$id'");
				
			
			    break;  
		     }	
             case "edit_loan_type":			 
			 {
				  $loan_type=mysqli_real_escape_string($con,trim($_POST['loan_type']));
			   
			     $loan_interest=mysqli_real_escape_string($con,trim($_POST['loan_interest']));
				  $id = $_POST['id'];
			
				if($loan_type!="" && $loan_interest!="")
				{
			  
			      if(is_numeric($loan_interest))
				  {
				      
                     mysqli_query($con,"UPDATE x_loantype SET  x_loan='$loan_type', x_loaninterest='$loan_interest' WHERE x_id='$id'");
					 
			         echo "done";
				  }
				  else
				  {
					  echo "notnumeric";
				  }
				}
				else{
					echo "empty";
				}
		
				break;
			 }
            
             case "approve_loan" :
			 { 
				 $loanreq_id = $_POST['id'];
				 $user_id = $_POST['userid'];
				 $total_amount = $_POST['totalamount'];
				
				//echo $sql = "UPDATE x_loanreq SET x_status='Y' WHERE x_id='$loanreq_id'";
				 mysqli_query($con,"UPDATE x_loanreq SET x_status='Y' WHERE x_id='$loanreq_id'");
				 
								
				 
				 $time_time = time();
				 $date = date("Y-m-d");
				 
				 mysqli_query($con,"INSERT INTO x_loan (x_loanreqid,x_time,x_totalamount,x_remainingamount,x_paidamount,x_approvedate)VALUES ('$loanreq_id','$time_time','$total_amount','$total_amount','0','$date')");
				 
				  $last_id = mysqli_insert_id($con);
				
			    //echo $sql ="SELECT b.x_nomonth,a.x_totalamount,b.x_approvedate,b.x_monthlypay FROM x_loan a INNER JOIN x_loanreq b ON a.x_loanreqid = b.x_id WHERE a.x_id = '$last_id'";
				// die();
				 $data_row =  mysqli_query($con,"SELECT b.x_nomonth,a.x_approvedate,a.x_totalamount,a.x_time,b.x_monthlypay FROM x_loan a INNER JOIN x_loanreq b ON a.x_loanreqid = b.x_id WHERE a.x_id = '$last_id'");
				 $data_array = mysqli_fetch_array($data_row);
				
				 $no_of_month = $data_array['x_nomonth'];
				 $approve_date = $data_array['x_approvedate'];
				 $total_amount = $data_array['x_totalamount'];
				 $monthly_payment = $data_array['x_monthlypay'];
				 $loan_accno = $data_array['x_time'];
				
                  for ($i = 0; $i < $no_of_month; $i++) 
					{
						$time = date('Y-m-d', strtotime('+1 month', strtotime($approve_date)));
						$approve_date = $time;
						//echo $approve_date."<br>";
						
						//echo $total_amount."<br>";
						//echo $sql = "INSERT INTO x_loanstatement (x_loanid,x_duepay,x_rembalance,x_duedate,x_status)VALUES('$last_id','$monthly_payment','$total_amount','$approve_date')";
						mysqli_query($con,"INSERT INTO x_loanstatement (x_loanid,x_duepay,x_rembalance,x_duedate,x_status)VALUES('$last_id','$monthly_payment','$total_amount','$approve_date','N')");
						$total_amount = $total_amount-$monthly_payment;
					}

				 $account_row = mysqli_query($con,"SELECT x_id,x_totalbalance,x_currencyid FROM x_anotheracc WHERE x_userid ='$user_id' AND x_for_main='main_account'");
				 $account_array = mysqli_fetch_array($account_row);				
				 
				 $acc_id = $account_array['x_id'];
				 $currency_id = $account_array['x_currencyid'];
				 $mainacc_bal = $account_array['x_totalbalance'];
				 
				 
				 // refer 218 for active loan account
				 $u_namex=user_bankuser($user_id,"x_fname")." ".user_bankuser($user_id,"x_lname");
				 
				 $msg_template=activated_mailertem($u_namex,$loan_accno);  
				 $u_phonenumber=user_bankuser($user_id,"x_phonenumber");
				 $admin_webmail=website_settingdata("x_webmail");
				 $to = user_bankuser($user_id,"x_email");
				 
                 $subject = "Your Loan account has been activated";

                 $message = $msg_template;

				 // Always set content-type when sending HTML email
				 $headers = "MIME-Version: 1.0" . "\r\n";
				 $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

				 // More headers
				 $headers .= 'From: <'.$admin_webmail.'>' . "\r\n";


				 //mail($to,$subject,$message,$headers);
				 sendMailSmtp($to,$subject,$message,$admin_webmail);
				 

                $sms_text='Dear '.$u_namex.' your Loan account have been created successfully. Your account number is '.$loan_accno.' . Enquiries call '.website_settingdata("x_contactnumber");
	 
	            sendsms($u_phonenumber,$sms_text);	
				
				//refer for transiction 329
				
				$currency_symbol = currency_data("x_currencysymbol",$currency_id);
				
				$final_amount = $data_array['x_totalamount'];
				
				$final_amountcomma = number_format($final_amount,2);
				
                $description_tr = "Loan Fund Credited".$currency_symbol." ".$final_amountcomma;
				
				
				mysqli_query($con,"INSERT into x_statement SET x_userid='$user_id', x_amount='$final_amount', x_type='credit', x_trdate='$date', x_description='$description_tr', x_fee='0', x_status='Y',x_acountid='$acc_id'");
				
				$statenentlast_id = mysqli_insert_id($con);
				
				//now total 
				 $now_totalbalance = $final_amount+$mainacc_bal;
				 mysqli_query($con,"UPDATE x_anotheracc SET x_totalbalance='$now_totalbalance' WHERE x_id='$acc_id'");
															
															
															
				
					
					//send mail to user
					$email_userbalance = user_bankuser($acc_id ,"x_totalbalance");
					$email_userbalance = number_format($email_userbalance,2);
					
					$e_username=user_bankuser($user_id,"x_fname").' '.user_bankuser($user_id,"x_lname");
					$e_useraccount=user_bankuser($acc_id,"x_time");
					$e_email=user_bankuser($user_id,"x_email");
					$u_phonenumber=user_bankuser($user_id,"x_phonenumber");
					$mailer_template=mailer_debitcredittempl($e_useraccount,$e_username,$description_tr,$statenentlast_id,$email_userbalance,$final_amountcomma,'credit',$currency_id);
					
					 $admin_webmail=website_settingdata("x_webmail");
					 $to =$e_email;
					 
                     $subject = "Transaction Notification Mail ";

                    $message = $mailer_template;

					// Always set content-type when sending HTML email
					$headers = "MIME-Version: 1.0" . "\r\n";
					$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

					// More headers
					$headers .= 'From: <'.$admin_webmail.'>' . "\r\n";


					//mail($to,$subject,$message,$headers);
					sendMailSmtp($to,$subject,$message,$admin_webmail);

					$tttx=date("l jS \of F Y h:i:s A");
					$sms_text='Credit Alert
					Acc: '.$e_useraccount.'
					Amt:'.$final_amountcomma.'
					Desc: '.$description_tr.' 
					Time:'.$tttx.'
					Avail Bal:'.$email_userbalance;
					sendsms($u_phonenumber,$sms_text);
															
					echo "done";
				
				 break;
				
			 }	

          /*   case "add_cds_interest":
			{
			      $min_amount = mysqli_real_escape_string($con,trim($_POST['min_amount']));
			   
			      $cds_interest = mysqli_real_escape_string($con,trim($_POST['interest_rate']));
			
				if($min_amount!="" && $cds_interest!="")
				{
			  
			      if(is_numeric($min_amount)&& is_numeric($cds_interest))
				  {
				       mysqli_query($con,"INSERT INTO x_cdssetting (	x_minimuminv,x_interest)VALUES('$min_amount','$cds_interest')");
					   
			            echo "done";
				  }
				  else
				  {
					  echo "notnumeric";
				  }
				}
				else{
					echo "empty";
				}
			break;  
		   }*/	

         /*   case "delete_cds_interest":
			 {
				
			    $id = $_POST['id'];
				mysqli_query($con,"DELETE FROM x_cdssetting WHERE x_id='$id'");
				
			
			    break;  
		     }*/
          case "edit_cds_interest":			 
			 {
				  $min_inves=mysqli_real_escape_string($con,trim($_POST['min_inv']));
			   
			     $cds_interest=mysqli_real_escape_string($con,trim($_POST['cds_interest']));
				 // $id = $_POST['id'];
			
				if($min_inves!="" && $cds_interest!="")
				{
			  
			      if(is_numeric($min_inves)&& is_numeric($cds_interest))
				  {
				      
                     mysqli_query($con,"UPDATE x_cdssetting SET  x_minimuminv='$min_inves', x_interest='$cds_interest' WHERE x_id='1'");
					 
			         echo "done";
				  }
				  else
				  {
					  echo "notnumeric";
				  }
				}
				else{
					echo "empty";
				}
		
				break;
			 }
			 
			 case "edit_investment_interest":			 
			 {
				  $min_inves=mysqli_real_escape_string($con,trim($_POST['min_inv']));
			   
			     $cds_interest=mysqli_real_escape_string($con,trim($_POST['cds_interest']));
				 // $id = $_POST['id'];
			
				if($min_inves!="" && $cds_interest!="")
				{
			  
			      if(is_numeric($min_inves)&& is_numeric($cds_interest))
				  {
				      
                     mysqli_query($con,"UPDATE x_investsetting SET  x_mininvest='$min_inves', x_interest='$cds_interest' WHERE x_id='1'");
					 
			         echo "done";
				  }
				  else
				  {
					  echo "notnumeric";
				  }
				}
				else{
					echo "empty";
				}
		
				break;
			 }
		
            case "approve_cds" :
			 { 
				 $cds_id = $_POST['id'];
				 $invest_amount = $_POST['investamount'];
				 $u_id = $_POST['userid'];
				 
				 $account_row = mysqli_query($con,"SELECT x_id,x_totalbalance,x_currencyid FROM x_anotheracc WHERE x_userid ='$u_id' AND x_for_main='main_account'");
				 $account_array = mysqli_fetch_array($account_row);				
				 
				 $acc_id = $account_array['x_id'];
				 $currency_id = $account_array['x_currencyid'];
				 $mainacc_bal = $account_array['x_totalbalance'];
				 
				 if( $mainacc_bal >= $invest_amount){
				 
				 $time_time = time();
				
				 $date = date("Y-m-d");
				
				//echo $swl = "UPDATE x_cds SET x_status='Y',x_investdate = '$date',x_time = '$time_time',x_maturestatus='N' WHERE x_id='$cds_id'";
				 mysqli_query($con,"UPDATE x_cds SET x_status='Y',x_investdate = '$date',x_time = '$time_time',x_maturestatus='N' WHERE x_id='$cds_id'");
				 				
				 $cds_row = mysqli_query($con,"SELECT * FROM x_cds WHERE x_id = '$cds_id'");
				 $cds_array = mysqli_fetch_array($cds_row);	
				 
				 $user_id = $cds_array['x_userid'];
				 $cds_accountno = $cds_array['x_time'];
				 $invest_amount = $cds_array['x_investamount'];
				 

				 
				//mail & smsfor activate cds
				 $u_namex=user_bankuser($user_id,"x_fname")." ".user_bankuser($user_id,"x_lname");
				 
				 $msg_template=activated_mailertem($u_namex,$cds_accountno);  
				 $u_phonenumber=user_bankuser($user_id,"x_phonenumber");
				 $admin_webmail=website_settingdata("x_webmail");
				 $to = user_bankuser($user_id,"x_email");
				 
                 $subject = "Your CDS has been activated";

                 $message = $msg_template;

				 // Always set content-type when sending HTML email
				 $headers = "MIME-Version: 1.0" . "\r\n";
				 $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

				 // More headers
				 $headers .= 'From: <'.$admin_webmail.'>' . "\r\n";


				 //mail($to,$subject,$message,$headers);
				 sendMailSmtp($to,$subject,$message,$admin_webmail);

                $sms_text='Dear '.$u_namex.' your CDS have been created successfully. Your account number is '.$cds_accountno.' . Enquiries call '.website_settingdata("x_contactnumber");
	 
	            sendsms($u_phonenumber,$sms_text);	
				
				//mail & sms for transiction debit cds
				
				$currency_symbol = currency_data("x_currencysymbol",$currency_id);
				
				
				$invest_amountcomma = number_format($invest_amount,2);
				
                $description_tr = "CDS Fund Debited".$currency_symbol." ".$invest_amountcomma;	
				
				mysqli_query($con,"INSERT into x_statement SET x_userid='$user_id', x_amount='$invest_amount', x_type='debit', x_trdate='$date', x_description='$description_tr', x_fee='0', x_status='Y',x_acountid='$acc_id'");
				
				$statenentlast_id = mysqli_insert_id($con);
				
				//now total 
				 $now_totalbalance = $mainacc_bal- $invest_amount;
				 mysqli_query($con,"UPDATE x_anotheracc SET x_totalbalance='$now_totalbalance' WHERE x_id='$acc_id'");
															
															
															
				
					
					//send mail to user
					$email_userbalance=user_bankuser($acc_id ,"x_totalbalance");
					$email_userbalance = number_format($email_userbalance,2);
					$e_username=user_bankuser($user_id,"x_fname").' '.user_bankuser($user_id,"x_lname");
					$e_useraccount=user_bankuser($acc_id,"x_time");
					$e_email=user_bankuser($user_id,"x_email");
					$u_phonenumber=user_bankuser($user_id,"x_phonenumber");
					$mailer_template=mailer_debitcredittempl($e_useraccount,$e_username,$description_tr,$statenentlast_id,$email_userbalance,$invest_amountcomma,'debit',$currency_id);
					
					 $admin_webmail=website_settingdata("x_webmail");
					 $to =$e_email;
					 
                     $subject = "Transaction Notification Mail ";

                    $message = $mailer_template;

					// Always set content-type when sending HTML email
					$headers = "MIME-Version: 1.0" . "\r\n";
					$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

					// More headers
					$headers .= 'From: <'.$admin_webmail.'>' . "\r\n";


					//mail($to,$subject,$message,$headers);
					sendMailSmtp($to,$subject,$message,$admin_webmail);

					$tttx=date("l jS \of F Y h:i:s A");
					$sms_text='Debit Alert
					Acc: '.$e_useraccount.'
					Amt:'.$invest_amountcomma.'
					Desc: '.$description_tr.' 
					Time:'.$tttx.'
					Avail Bal:'.$email_userbalance;
					sendsms($u_phonenumber,$sms_text);
															
					echo "done";
				 }
				 else{
					 echo "minbal";
				 }
				
				 break;
				
			 }	
			 
			 case "approve_investment" :
			 { 
				 $invreq_id = $_POST['id'];
				 $user_id = $_POST['userid'];
				 $invest_amount = $_POST['investamount'];
				 
				 
				 
				 $account_row = mysqli_query($con,"SELECT x_id,x_totalbalance,x_currencyid FROM x_anotheracc WHERE x_userid ='$user_id' AND x_for_main='main_account'");
				 
				 $account_array = mysqli_fetch_array($account_row);				
				 $acc_id = $account_array['x_id'];
				 $currency_id = $account_array['x_currencyid'];
				 $mainacc_bal = $account_array['x_totalbalance'];
				 
				 if( $mainacc_bal >= $invest_amount)
				 {
				     $time_time = time();
				     $date = date("Y-m-d");
				
				
					//echo $sql = "UPDATE x_investment SET x_status='Y' WHERE x_id='$invreq_id'";
					
					 mysqli_query($con,"UPDATE x_investment SET x_status='Y',x_invdate = '$date' ,x_time = '$time_time' WHERE x_id='$invreq_id'");
					 
		            //  $sql = "Select * from x_investment where x_id ='$invreq_id'";
		
					 $data_row =  mysqli_query($con,"Select * from x_investment where x_id ='$invreq_id'");
					 
					 $data_array = mysqli_fetch_array($data_row);
					
					 $inv_period = $data_array['x_invperiod'];
					 $inv_period = str_replace(" years","",$inv_period);
					
					 $interet_period = $data_array['x_interestreq'];
					 $total_installment = $inv_period * $interet_period;
					
					 $inv_date = $data_array['x_invdate'];
					 $interest_earn = $data_array['x_interestearn'];
					 $new_interest = $interest_earn / $total_installment;
					 $inv_accno = $data_array['x_time'];
				
                  for ($i = 0; $i < $total_installment; $i++) 
					{
						if($interet_period =="1")
						{
							$time = date('Y-m-d', strtotime('+1 year', strtotime($inv_date)));
						}
						else if($interet_period =="2")
						{
							$time = date('Y-m-d', strtotime('+6 month', strtotime($inv_date)));
						}
                        else if($interet_period =="4")
						{
							$time = date('Y-m-d', strtotime('+4 month', strtotime($inv_date)));
						}
                        else if($interet_period =="12")
						{
							$time = date('Y-m-d', strtotime('+1 month', strtotime($inv_date)));
						}						
						
						 $inv_date = $time;
						
						//echo $sql = "INSERT INTO x_investmentstatement (	x_userid,x_reciveinterest,x_recivedate,x_status)VALUES('$user_id','$new_interest','$inv_date','N')";
						
						mysqli_query($con,"INSERT INTO x_investmentstatement (	x_userid,x_invid,x_reciveinterest,x_recivedate,x_status)VALUES('$user_id','$invreq_id','$new_interest','$inv_date','N')");
						
					}
					

				 $account_row = mysqli_query($con,"SELECT x_id,x_totalbalance,x_currencyid FROM x_anotheracc WHERE x_userid ='$user_id' AND x_for_main='main_account'");
				 
				 $account_array = mysqli_fetch_array($account_row);				
				 
				 $acc_id = $account_array['x_id'];
				 $currency_id = $account_array['x_currencyid'];
				 $mainacc_bal = $account_array['x_totalbalance'];
				 
				 $investment_row = mysqli_query($con,"SELECT * from x_investment where x_id='$invreq_id'");
				 
				 $investment_array = mysqli_fetch_array($investment_row);
                   
                 $inv_accno =  $investment_array ['x_time'];
                 			 
				 
				 
				 // for active invest account
				 $u_namex=user_bankuser($user_id,"x_fname")." ".user_bankuser($user_id,"x_lname");
				 
				 $msg_template=activated_mailertem($u_namex,$inv_accno);  
				 $u_phonenumber=user_bankuser($user_id,"x_phonenumber");
				 $admin_webmail=website_settingdata("x_webmail");
				 $to = user_bankuser($user_id,"x_email");
				 
                 $subject = "Your Investment account has been activated";

                 $message = $msg_template;

				 // Always set content-type when sending HTML email
				 $headers = "MIME-Version: 1.0" . "\r\n";
				 $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

				 // More headers
				 $headers .= 'From: <'.$admin_webmail.'>' . "\r\n";


				//mail($to,$subject,$message,$headers);
				sendMailSmtp($to,$subject,$message,$admin_webmail);

                $sms_text='Dear '.$u_namex.' your Investment account have been created successfully. Your account number is '.$inv_accno.' . Enquiries call '.website_settingdata("x_contactnumber");
	 
	            sendsms($u_phonenumber,$sms_text);	
				
				//for investment transaction
				
				$currency_symbol = currency_data("x_currencysymbol",$currency_id);
				
				//$final_amount = $data_array['x_totalamount'];
				
				$invest_amountcomma = number_format($invest_amount,2);
				
                $description_tr = "Investment Fund Debited ".$currency_symbol." ".$invest_amountcomma;	
				
				mysqli_query($con,"INSERT into x_statement SET x_userid='$user_id', x_amount='$invest_amount', x_type='debit', x_trdate='$date', x_description='$description_tr', x_fee='0', x_status='Y',x_acountid='$acc_id'");
				
				$statenentlast_id = mysqli_insert_id($con);
				
				//now total 
				 $now_totalbalance = $mainacc_bal - $invest_amount;
				 mysqli_query($con,"UPDATE x_anotheracc SET x_totalbalance='$now_totalbalance' WHERE x_id='$acc_id'");
															
															
															
				
					
					//send mail to user
					$email_userbalance=user_bankuser($acc_id ,"x_totalbalance");
					$email_userbalance = number_format($email_userbalance,2);
					$e_username=user_bankuser($user_id,"x_fname").' '.user_bankuser($user_id,"x_lname");
					$e_useraccount=user_bankuser($acc_id,"x_time");
					$e_email=user_bankuser($user_id,"x_email");
					$u_phonenumber=user_bankuser($user_id,"x_phonenumber");
					$mailer_template=mailer_debitcredittempl($e_useraccount,$e_username,$description_tr,$statenentlast_id,$email_userbalance,$invest_amountcomma,'debit',$currency_id);
					
					 $admin_webmail=website_settingdata("x_webmail");
					 $to =$e_email;
					 
                     $subject = "Transaction Notification Mail ";

                    $message = $mailer_template;

					// Always set content-type when sending HTML email
					$headers = "MIME-Version: 1.0" . "\r\n";
					$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

					// More headers
					$headers .= 'From: <'.$admin_webmail.'>' . "\r\n";


					//mail($to,$subject,$message,$headers);
					sendMailSmtp($to,$subject,$message,$admin_webmail);

					$tttx=date("l jS \of F Y h:i:s A");
					$sms_text='Debit Alert
					Acc: '.$e_useraccount.'
					Amt:'.$invest_amountcomma.'
					Desc: '.$description_tr.' 
					Time:'.$tttx.'
					Avail Bal:'.$email_userbalance;
					sendsms($u_phonenumber,$sms_text);
															
					echo "done";
				 }
				 else{
					 echo "minbal";
				 }
				
				 break;
				
			 }	
			 
			 
			 
			  case "approve_mature_cds" :
			 { 
				 $cds_id = $_POST['id'];
				 $matured_amount = $_POST['maturedamount'];
				 $u_id = $_POST['userid'];
				
				 
				 $account_row = mysqli_query($con,"SELECT x_id,x_totalbalance,x_currencyid FROM x_anotheracc WHERE x_userid ='$u_id' AND x_for_main='main_account'");
				 $account_array = mysqli_fetch_array($account_row);				
				 
				 $acc_id = $account_array['x_id'];
				 $currency_id = $account_array['x_currencyid'];
				 $mainacc_bal = $account_array['x_totalbalance'];
				 
			
				 mysqli_query($con,"UPDATE x_cds SET x_maturestatus='C' WHERE x_id='$cds_id'");
				
				
				 $cds_row = mysqli_query($con,"SELECT * FROM x_cds WHERE x_id = '$cds_id'");
				 $cds_array = mysqli_fetch_array($cds_row);	
				 
				 $user_id = $cds_array['x_userid'];
				 $cds_accountno = $cds_array['x_time'];
				 //$invest_amount = $cds_array['x_investamount'];
				 
				
				//mail & sms for transiction debit cds
				
				$currency_symbol = currency_data("x_currencysymbol",$currency_id);
				
				$date = date("Y-m-d");
				
				$matured_amountcomma = number_format($matured_amount,2);
				
                $description_tr = "CDS Fund Credited".$currency_symbol." ".$matured_amountcomma;	
				
				mysqli_query($con,"INSERT into x_statement SET x_userid='$user_id', x_amount='$matured_amount', x_type='credit', x_trdate='$date', x_description='$description_tr', x_fee='0', x_status='Y',x_acountid='$acc_id'");
				
				$statenentlast_id = mysqli_insert_id($con);
				
				//now total 
				 $now_totalbalance = $mainacc_bal + $matured_amount;
				 mysqli_query($con,"UPDATE x_anotheracc SET x_totalbalance='$now_totalbalance' WHERE x_id='$acc_id'");
															
				
					//send mail to user
					$email_userbalance=user_bankuser($acc_id ,"x_totalbalance");
					$email_userbalance = number_format($email_userbalance,2);
					$e_username=user_bankuser($user_id,"x_fname").' '.user_bankuser($user_id,"x_lname");
					$e_useraccount=user_bankuser($acc_id,"x_time");
					$e_email=user_bankuser($user_id,"x_email");
					$u_phonenumber=user_bankuser($user_id,"x_phonenumber");
					$mailer_template=mailer_debitcredittempl($e_useraccount,$e_username,$description_tr,$statenentlast_id,$email_userbalance,$matured_amountcomma,'credit',$currency_id);
					
					 $admin_webmail=website_settingdata("x_webmail");
					 $to =$e_email;
					 
                     $subject = "Transaction Notification Mail ";

                    $message = $mailer_template;

					// Always set content-type when sending HTML email
					$headers = "MIME-Version: 1.0" . "\r\n";
					$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

					// More headers
					$headers .= 'From: <'.$admin_webmail.'>' . "\r\n";


					//mail($to,$subject,$message,$headers);
					sendMailSmtp($to,$subject,$message,$admin_webmail);

					$tttx=date("l jS \of F Y h:i:s A");
					$sms_text='Credit Alert
					Acc: '.$e_useraccount.'
					Amt:'.$matured_amountcomma.'
					Desc: '.$description_tr.' 
					Time:'.$tttx.'
					Avail Bal:'.$email_userbalance;
					sendsms($u_phonenumber,$sms_text);
															
					echo "done";
				
				
				 break;
				
			 }	
  
   case "approve_invest_mainbal" :
			 { 
				 $invest_id = $_POST['id'];
				 $invest_amount = $_POST['investamount'];
				 $u_id = $_POST['userid'];
				
				 
				 $account_row = mysqli_query($con,"SELECT x_id,x_totalbalance,x_currencyid FROM x_anotheracc WHERE x_userid ='$u_id' AND x_for_main='main_account'");
				 $account_array = mysqli_fetch_array($account_row);				
				 
				 $acc_id = $account_array['x_id'];
				 $currency_id = $account_array['x_currencyid'];
				 $mainacc_bal = $account_array['x_totalbalance'];
				 
			
				 mysqli_query($con,"UPDATE x_investment SET x_reqbal='C' WHERE x_id='$invest_id'");
				
				
				 $invest_row = mysqli_query($con,"SELECT * FROM x_investment WHERE x_id = '$invest_id'");
				 $invest_array = mysqli_fetch_array($invest_row);	
				 
				 $user_id = $invest_array['x_userid'];
				 $invest_accountno = $invest_array['x_time'];
				 //$invest_amount = $cds_array['x_investamount'];
				 
				
				//mail & sms for transiction debit cds
				
				$currency_symbol = currency_data("x_currencysymbol",$currency_id);
				
				$date = date("Y-m-d");
				
				$invest_amountcomma = number_format($invest_amount,2);
				
                $description_tr = "Investment Main Fund Credited".$currency_symbol." ".$invest_amountcomma;	
				
				mysqli_query($con,"INSERT into x_statement SET x_userid='$user_id', x_amount='$invest_amount', x_type='credit', x_trdate='$date', x_description='$description_tr', x_fee='0', x_status='Y',x_acountid='$acc_id'");
				
				$statenentlast_id = mysqli_insert_id($con);
				
				//now total 
				 $now_totalbalance = $mainacc_bal + $invest_amount;
				 mysqli_query($con,"UPDATE x_anotheracc SET x_totalbalance='$now_totalbalance' WHERE x_id='$acc_id'");
															
				
					//send mail to user
					$email_userbalance=user_bankuser($acc_id ,"x_totalbalance");
					$email_userbalance = number_format($email_userbalance,2);
					$e_username=user_bankuser($user_id,"x_fname").' '.user_bankuser($user_id,"x_lname");
					$e_useraccount=user_bankuser($acc_id,"x_time");
					$e_email=user_bankuser($user_id,"x_email");
					$u_phonenumber=user_bankuser($user_id,"x_phonenumber");
					$mailer_template=mailer_debitcredittempl($e_useraccount,$e_username,$description_tr,$statenentlast_id,$email_userbalance,$invest_amountcomma,'credit',$currency_id);
					
					 $admin_webmail=website_settingdata("x_webmail");
					 $to =$e_email;
					 
                     $subject = "Transaction Notification Mail ";

                    $message = $mailer_template;

					// Always set content-type when sending HTML email
					$headers = "MIME-Version: 1.0" . "\r\n";
					$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

					// More headers
					$headers .= 'From: <'.$admin_webmail.'>' . "\r\n";


					//mail($to,$subject,$message,$headers);
					sendMailSmtp($to,$subject,$message,$admin_webmail);

					$tttx=date("l jS \of F Y h:i:s A");
					$sms_text='Credit Alert
					Acc: '.$e_useraccount.'
					Amt:'.$invest_amountcomma.'
					Desc: '.$description_tr.' 
					Time:'.$tttx.'
					Avail Bal:'.$email_userbalance;
					sendsms($u_phonenumber,$sms_text);
															
					echo "done";
				
				
				 break;
				
			 }

     case "upload_forms_pdf":
	 {
		 $form_name = $_POST['formname'];
		 $pdf_file =$_FILES["pdf_file"]["name"];
		 
		 if($form_name == "" || $pdf_file == "")
		 {
			   echo "empty";
		 }
		 else
		 {
			 
			  $my_filename = $_FILES["pdf_file"]["name"];
			  
			   $my_filesize = $_FILES["pdf_file"]["size"];
			   $my_filetype = $_FILES["pdf_file"]["type"];
			   $my_fileerror = $_FILES["pdf_file"]["error"];
			   $my_filetempname=$_FILES["pdf_file"]["tmp_name"];
			   $my_filepath="../user/pdfs/";
									
			   $gg_filef=pdfuploader($my_filename, $my_filetype, $my_filesize, $my_fileerror, $my_filetempname, $my_filepath); 
			  
		        if(($gg_filef=="wrongfile")||($gg_filef=="errorfile"))    
				{
					if($gg_filef=="wrongfile") 
					{
						echo 'wrongfile';  
					}
					else
					{
						echo 'errorfile';  
					}
				}
			    else
				{
					//echo $sql = "INSERT into x_formspdf SET x_pdf='$gg_filef', x_name='$form_name'";
				   mysqli_query($con,"INSERT into x_formspdf SET x_pdf='$gg_filef', x_name='$form_name'");
				   
				   echo "done";
				}
		 }
		 
		 break;
	 }	


      case "delete_pdf_forms":
	  {
		  $id = $_POST['id'];
		 
		  mysqli_query($con, "delete from x_formspdf where x_id = '$id'");
		  
		  break;
	  }	 
  
	  case "send_notification":
	  {
		    $id = $_POST['id'];
			$msg = $_POST['msg'];
		    $sub = $_POST['sub'];
			$msg=addslashes($msg);
			 if($msg == "" || $sub == ""){
				 echo "empty";
			 }
			 else{
				  $sql = "INSERT into x_notification SET x_userid = '$id',x_message='$msg',x_subject='$sub',x_status='U'";
	
				 mysqli_query($con,$sql);
				 echo "done";
			 }
			break;
	  }			 

     case "send_sms":
	 {
		 $id = $_POST['id'];
		 $sms = $_POST['sms'];
		 
		 if($sms == "")
		 {
			 echo "empty";
		 }
		 else
		 {
			  $bank_name = website_settingdata("x_bankname");
			  $u_phonenumber = user_bankuser($user_id,"x_phonenumber");
			  
			 
			  
				   $tttx=date("l jS \of F Y h:i:s A");
				   
					echo $sms_text= "$bank_name Alert
					Desc: $sms 
					Time: $tttx ";
					
					sendsms($u_phonenumber,$sms_text); 
		 }
		break;
	 }

		//next case here  
				  }
			  
			  
			  
		  }
