<?php
class Database {
	function create_database($data)
	{
		$mysqli = new mysqli($data['hostname'],$data['username'],$data['password'],'');
		if(mysqli_connect_errno())
			return false;

		$mysqli->query("IF NOT EXISTS ".$data['database']);
		
		return true;
		$mysqli->close();
	}

	function create_tables($data)
	{
		$mysqli = new mysqli($data['hostname'],$data['username'],$data['password'],'');
		if(mysqli_connect_errno())
			return false;

		if (!$mysqli->select_db($data['database'])) {
		    $msg = "Sorry ".$data['database']." databse NOT EXISTS Please import database first";
			return ['st'=>false,'msg'=>$msg];
		}else{
			return ['st'=>true,'msg'=>''];
		}
	}

	function registration($data){
		$conn = new mysqli($data['hostname'],$data['username'],$data['password'],$data['database']);
		if(mysqli_connect_errno())
			return false;

		$siteUrl =  str_replace(basename($_SERVER['SCRIPT_NAME']), '',$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']);
		$siteUrl = str_replace('update/', '', $siteUrl);
		$siteUrl = preg_replace('#(^https?:\/\/(w{3}\.)?)|(\/$)#', '', $siteUrl);
		$siteUrl = str_replace('www.','',$siteUrl);
		$siteUrl = str_replace('/.','',$siteUrl);
		$siteUrl = $siteUrl.'/';
		$dt = new DateTime('now',new DateTimezone('Asia/Dhaka'));
		$date = $dt->format('Y-m-d H:i:s');
		$conn->query("SET sql_mode = ''");
			$old_version = 4.2;
			$new_version = 4.3;

			$dt = new DateTime('now',new DateTimezone('Asia/Dhaka'));
			$date = $dt->format('Y-m-d H:i:s');

			$get = "SELECT * FROM setting";
			$result = $conn->query($get); 
			if($result->num_rows > 0):
				while ($row = $result-> fetch_array()) {



					if($row['version'] < 2.7):
					  	$msg = "You are missing some version. Please contact use to update";
					  	return ['st'=>false,'msg'=>$msg];
					  	exit();
					endif;


					if($row['version']== $new_version):
					  	$msg = "You are using updated version. Thank you!";
					  	return ['st'=>false,'msg'=>$msg];
					  	exit();
					endif;


					


					if($row['version'] < 2.9){
						$new_version = 2.9;
						$st_1 = $conn->query("INSERT INTO language_data(keyword,type,english) VALUES 
						('read_terms','admin','I have read the Terms & Condition and accept them.'),
						('your_name','admin','Your name'),
						('version','admin','version'),
						('add_unlimited_portfolios','admin','You can add  Unlimited Portfolios'),
						('reached_limit','admin','You reached the maximum limit'),
						('info','admin','Info'),
						('alert','admin','alert'),
						('sorry','admin','Sorry'),
						('you_have_remaining','admin','you have remaining'),
						('portfolios_out_of','admin','Portfolios out of'),
						('video','admin','video'),
						('add_link','admin','Add Link'),
						('runing_package','admin','Runing Package'),
						('package_expired','admin','Your package will expire after'),
						('reactive_msg','admin','Your package is expired. you can re-active it again'),
						('start_time','admin','Start Time'),
						('end_time','admin','End Time'),
						('days','admin','Days'),
						('empty_as_present','admin','Empty define as present'),
						('facts','admin','Facts Item'),
						('total','admin','Total'),
						('member_since','admin','Member Since'),
						('last_login','admin','Last Login'),
						('de_active_msg','admin','Want to deactive your account?'),
						('ac_active_msg','admin','Want to active your account?'),
						('average_based_on','admin','average based on'),
						('upload_pdf','admin','Upload pdf'),
						('uploaded_msg','admin','Pdf already Uploaded. Click upload again'),
						('time_picker','admin','Time Picker'),
						('paypal_business_email','admin','paypal business email'),
						('yes','admin','Yes'),
						('no','admin','no'),
						('are_you_sure','admin','Are you sure'),
						('reset_pass_msg','admin','Want to reset password?'),
						('contact_with_phone','admin','Contact with Phone'),
						('present','admin','Present'),
						('male','admin','Male'),
						('female','admin','Female'),
						('share_on_facebook','admin','Share on facebook'),
						('download_resume','admin','Download my resume'),
						('send_me_message','admin','Send me a messege'),
						('account_not_approve','admin','Your account is not approved'),
						('invalid_login','admin','Login invalid'),
						('login_success','admin','Login Successfull'),
						('all','admin','all')") or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$dt = new DateTime('now',new DateTimezone('Asia/Dhaka'));
					   	$date = $dt->format('Y-m-d H:i:s');
						$update = "UPDATE setting SET version=$new_version,updated_at='$date' WHERE id=".$row['id'];
						$insert = $conn->query($update);
						
					}

					// update 3.0
					if($row['version'] < 3.0){
						$new_version = 3.0;
							$st_1 = $conn->query('ALTER TABLE setting ADD (is_offline INT(11) NOT NULL DEFAULT 1)') or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query('ALTER TABLE home ADD (about_me_long TEXT NULL)') or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query('ALTER TABLE users ADD (qr_code VARCHAR(255) NOT NULL)') or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query('ALTER TABLE social_sites ADD (is_profile INT(11) NOT NULL DEFAULT 1)') or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query("INSERT INTO language_data(keyword,type,english) VALUES 
							('about_me_overview','admin','About ME (overview)'),
							('payment_not_available','admin','Payment is not available'),
							('qr_code','admin','QR code'),
							('download','admin','Download'),
							('share_qr','admin','Share Qr'),
							('other','admin','Others'),
							('icon_for','admin','Icon For'),
							('copy_qr_link','admin','Copy QR link'),
							('is_profile','admin','Is Profile'),
							('offline_payments','admin','Offline Payments')") or print json_encode(array('st'=>0,'msg'=>$conn->error));



						$dt = new DateTime('now',new DateTimezone('Asia/Dhaka'));
					   	$date = $dt->format('Y-m-d H:i:s');
						$update = "UPDATE setting SET version=$new_version,updated_at='$date' WHERE id=".$row['id'];
						$insert = $conn->query($update);
						
					}

					// update 3.1
					if($row['version'] < 3.1){
						$new_version = 3.1;
						$st_1 = $conn->query('ALTER TABLE users ADD (dial_code VARCHAR(255) NOT NULL )') or print json_encode(array('st'=>0,'msg'=>$conn->error));
								 		
						$st_1 = $conn->query('ALTER TABLE setting ADD (is_user INT(11) NOT NULL DEFAULT 1, is_review INT(11) NOT NULL DEFAULT 1, is_contact INT(11) NOT NULL DEFAULT 1 )') or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query("INSERT INTO language_data(keyword,type,english) VALUES 
						('dial_code','admin','Dial Code')") or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query("INSERT INTO features(id,features,slug,status,created_at) VALUES 
							('14','QR code','qr_code','1','2021-04-17 23:04:31')") or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$dt = new DateTime('now',new DateTimezone('Asia/Dhaka'));
					   	$date = $dt->format('Y-m-d H:i:s');
						$update = "UPDATE setting SET version=$new_version,updated_at='$date' WHERE id=".$row['id'];
						$insert = $conn->query($update);
						
					}

					// update 3.2
					if($row['version'] < 3.2){
						$new_version = 3.2;
						$st_1 = $conn->query("INSERT INTO language_data(keyword,type,english) VALUES 
							('contact_with_phone','admin','Contact with phone'),
							('whatsapp_number','admin','whatsapp number'),
							('only_vcard','admin','Only vcard'),
							('only_profile','admin','Only Profile'),
							('both','admin','Both'),
							('share_with','admin','Share With'),
							('vcard_themes','admin','vcard themes'),
							('profile','admin','Profile'),
							('website','admin','Website')") or print json_encode(array('st'=>0,'msg'=>$conn->error));


						$st_1 = $conn->query("INSERT INTO `features` (`id`, `features`, `slug`, `status`, `created_at`) VALUES
							(15, 'Vcard', 'vcard', 1, '2021-05-02 23:04:31')") or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query('ALTER TABLE users ADD (cover_photo VARCHAR(255) NOT NULL, whatsapp VARCHAR(255) NOT NULL, vcard_status INT(11) NOT NULL DEFAULT 2, vcard_layouts INT(11) NOT NULL DEFAULT 1)') or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$dt = new DateTime('now',new DateTimezone('Asia/Dhaka'));
					   	$date = $dt->format('Y-m-d H:i:s');
						$update = "UPDATE setting SET version=$new_version,updated_at='$date' WHERE id=".$row['id'];
						$insert = $conn->query($update);
						
					}

					//update 3.3
					if($row['version'] < 3.3){
						$new_version = 3.3;
						$st_1 = $conn->query('ALTER TABLE setting ADD (seo_settings text  NULL)') or print json_encode(array('st'=>0,'msg'=>$conn->error));

					 	$st_1 = $conn->query('ALTER TABLE user_settings ADD (seo_settings text  NULL)') or print json_encode(array('st'=>0,'msg'=>$conn->error));

					 	$st_1 = $conn->query('ALTER TABLE users ADD (vcard_bg_color VARCHAR(255) DEFAULT "e43f5a")') or print json_encode(array('st'=>0,'msg'=>$conn->error));

					 	$st_1 = $conn->query("INSERT INTO language_data(keyword,type,english) VALUES 
						('seo_settings','admin','Seo Settings'),
						('keyword','admin','keywords'),
						('description','admin','description'),
						('keywords','label','keywords')") or print json_encode(array('st'=>0,'msg'=>$conn->error));


						$dt = new DateTime('now',new DateTimezone('Asia/Dhaka'));
					   	$date = $dt->format('Y-m-d H:i:s');
						$update = "UPDATE setting SET version=$new_version,updated_at='$date' WHERE id=".$row['id'];
						$insert = $conn->query($update);
						
					}

					if($row['version'] < 3.4){
						$new_version = 3.4;
						$st_1 = $conn->query('ALTER TABLE setting ADD (active_key VARCHAR(155) NULL,site_url VARCHAR(155) NULL)') or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query("INSERT INTO language_data(keyword,type,english) VALUES 
						('check_mail','admin','Check mail'),
						('test_mail','admin','test mail')") or print json_encode(array('st'=>0,'msg'=>$conn->error));
						$update = "UPDATE setting SET version=$new_version,updated_at='$date' WHERE id=".$row['id'];
						$insert = $conn->query($update);

					}

					if($row['version'] < 3.5){
						$new_version = 3.5;


						$query = '';
						$sqlScript = file('tables/update_3_5.sql');

						foreach ($sqlScript as $line)	{
							
							$startWith = substr(trim($line), 0 ,2);
							$endWith = substr(trim($line), -1 ,1);
							
							if (empty($line) || $startWith == '--' || $startWith == '/*' || $startWith == '//') {
								continue;
							}
							
							$query = $query . $line;
							if ($endWith == ';') {
								mysqli_query($conn,$query) or die('<div class="error-response sql-import-response">Problem in executing the SQL query <b>' . $query. '</b></div>');
								$query= '';		
							}
						}



						$st_1 = $conn->query('ALTER TABLE services ADD (service_type INT(11) NOT NULL DEFAULT 1,video_link TEXT NULL,overview TEXT NULL)') or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query('ALTER TABLE services ADD (price DOUBLE NOT NULL,is_order INT(11))') or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query('ALTER TABLE setting ADD (is_update INT(11) NOT NULL DEFAULT 0,license VARCHAR(155) NULL,site_info VARCHAR(155) NULL,license_code VARCHAR(155) NULL,is_test INT(11) NOT NULL DEFAULT 0)') or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query('ALTER TABLE users ADD (full_name VARCHAR(155) NULL)') or print json_encode(array('st'=>0,'msg'=>$conn->error));
						$st_1 = $conn->query('ALTER TABLE features_type ADD (vcard_limit int(11) NULL  DEFAULT 2)') or print json_encode(array('st'=>0,'msg'=>$conn->error));


						$st_1 = $conn->query("INSERT INTO language_data(keyword,type,english) VALUES 
						('add_video_link','admin','Add video link'),
						('video','admin','video'),
						('service_settings','admin','service settings'),
						('paypal_business_email','admin','Paypal business email'),
						('stripe_payment','admin','Stripe payment'),
						('stripe_public_key','admin','Stripe Public key'),
						('stripe_secret_key','admin','Stripe Secret key'),
						('razorpay_payment','admin','razorpay payment'),
						('razorpay_key','admin','razorpay key'),
						('mode','admin','Mode'),
						('inactive','admin','Inactive'),
						('payment_method','admin','Payment Method'),
						('select','admin','Select'),
						('bank_details','admin','Bank Details'),
						('login','admin','Login'),
						('new_registration','admin','New Registration'),
						('already_have_account','admin','Already have account'),
						('registration_successfull','admin','Registration Successfull'),
						('payment_failed','admin','Payment Failed'),
						('payment_success','admin','Payment Success'),
						('country','admin','Country'),
						('personal_info','admin','Personal Info'),
						('order','admin','Order'),
						('orders','admin','Orders'),
						('service','admin','service'),
						('price','admin','price'),
						('customer_panel','admin','Customer Panel'),
						('approved','admin','Approved'),
						('rejected','admin','Rejected'),
						('customer_name','admin','Customer name'),
						('payment_status','admin','Payment status'),
						('order_status','admin','Order status'),
						('save','admin','save'),
						('background_color_picker','admin','Background color picker'),
						('vcard_cover_photo','admin','vCard cover photo'),
						('not_installed','admin','Not Installed'),
						('installed','admin','Installed'),
						('install','admin','Install'),
						('vcf_information','admin','VCF (Virtual Contact File) Information'),
						('field_limit_exists','admin','Limit exceed, please upgrade your membership'),
						('vcard_information_limit','admin','vCard Information Limit'),
						('completed','admin','Completed')") or print json_encode(array('st'=>0,'msg'=>$conn->error));



						$st_1 = $conn->query("INSERT INTO language_data(keyword,type,english) VALUES 
						('customer_phone','admin','Customer Phone'),
						('addons','admin','Addons'),
						('order_list','admin','Order List'),
						('vacrd','admin','vCard'),
						('add_information','admin','Add Information'),
						('order_now','admin','Order Now'),
						('contact','admin','Contact'),
						('upgrade','admin','Upgrade')") or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query("INSERT INTO language_data(keyword,type,english) VALUES 
						('seller_information','label','Seller information'),
						('service_info','label','Service Info'),
						('home','label','Home'),
						('bank_details','admin','Bank Details')") or print json_encode(array('st'=>0,'msg'=>$conn->error));


						
					   	$insert = $conn->query("UPDATE setting SET version=$new_version,updated_at='$date',is_update='1' WHERE id=".$row['id']);
					}


					if($row['version'] < 3.6){
						$new_version = 3.6;


						$st_1 = $conn->query('ALTER TABLE setting ADD (purchase_date DATETIME NULL, key_id VARCHAR(255) NULL)') or print json_encode(array('st'=>0,'msg'=>$conn->error));
						$st_1 = $conn->query('ALTER TABLE users ADD (active_vcard int(11) NULL  DEFAULT 0)') or print json_encode(array('st'=>0,'msg'=>$conn->error));


						$st_1 = $conn->query("INSERT INTO language_data(keyword,type,details,english) VALUES 
						('values', 'admin', 'Values', 'Values'),
						( 'qty', 'admin', 'QTY', 'QTY'),
						( 'language_data', 'admin', 'Languages Data', 'Languages Data'),
						( 'offline_request', 'admin', 'Offline Request', 'Offline Request'),
						( 'service_info', 'admin', 'Service Information', 'Service Information'),
						( 'seller_information', 'admin', 'Seller Information', 'Seller Information'),
						( 'close', 'admin', 'Close', 'Close'),
						( 'razorpay', 'admin', 'Razorpay', 'Razorpay'),
						( 'customer_information', 'admin', 'Customer Information', 'Customer Information'),
						( 'key_id', 'admin', 'Razorpay Key Id', 'Razorpay Key Id'),
						( 'enable_to_allow_signup_system', 'admin', 'Enable to allow sign up users to your system', 'Enable to allow sign up users to your system'),
						( 'enable_to_allow_auto_approve', 'admin', 'Enable to allow auto-approved when users sign up to your system', 'Enable to allow auto-approved when users sign up to your system'),
						( 'enable_to_allow_email_verification', 'admin', 'Enable to allow email verification when users sign up to your system', 'Enable to allow email verification when users sign up to your system'),
						( 'get_admin_invoice_mail', 'admin', 'Admin will get an invoice after make a new registration', 'Admin will get an invoice after make a new registration'),
						( 'admin_new_user_mail', 'admin', 'Admin will get an email after make a new registration', 'Admin will get an email after make a new registration'),
						( 'new_use_invoice', 'admin', 'User will get an Invoice after make a  registration', 'User will get an Invoice after make a  registration'),
						( 'account_counter_in_landing_page', 'admin', 'Show All account counter in landing page', 'Show All account counter in landing page'),
						( 'show_ads_in_free_user_profile', 'admin', 'Show Ads in Free User\'s profile', 'Show Ads in Free User\'s profile'),
						( 'enable_offilne_payment_request', 'admin', 'Enable Offline Payments request', 'Enable Offline Payments request'),
						( 'admin_invoice', 'admin', 'Admin invoice', 'admin invoice'),
						( 'new_user_mail', 'admin', 'New User Mail', 'New User Mail'),
						( 'preferences', 'admin', 'Preferences', 'preferences'),
						( 'twillo_sms_settings', 'admin', 'Twillo sms settings', 'twillo sms settings'),
						( 'email_settings', 'admin', 'Email settings', 'email settings'),
						( 'payment_settings', 'admin', 'Payment settings', 'Payment settings'),
						( 'recaptcha_settings', 'admin', 'Recaptcha Settings', 'Recaptcha Settings'),
						( 'general', 'admin', 'General', 'General'),
						( 'documentaion', 'admin', 'Documentaion', 'Documentaion'),
						( 'vcard_enable_msg', 'admin', 'If you enable the new vCard then you have to re-insert card information. after enabling the vCard you can\'t disable it anymore.', 'If you enable the new vCard then you have to re-insert card information. after enabling the vCard you can\'t disable it anymore.')") or print json_encode(array('st'=>0,'msg'=>$conn->error));

						
						
					   	$insert = $conn->query("UPDATE setting SET version=$new_version,updated_at='$date',is_update='1' WHERE id=".$row['id']);
					}


					if($row['version'] < 3.7){
						$new_version = 3.7;

						$st_1 = $conn->query('ALTER TABLE users ADD (vcard_icon_color VARCHAR(255) NULL  DEFAULT "ea0599")') or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query('ALTER TABLE setting ADD (demo_username VARCHAR(255) NULL,is_user_demo INT(11) default 0,is_vcard_theme INT(11) default 1 )') or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query('ALTER TABLE setting ADD (environment VARCHAR(255) NULL  DEFAULT "live")') or print json_encode(array('st'=>0,'msg'=>$conn->error));


						$st_1 = $conn->query("INSERT INTO language_data(keyword,type,details,english) VALUES 
						('add_to_contact', 'admin', 'Add to contact', 'Add to contact'),
						( 'mail_sent', 'admin', 'Mail sent', 'Mail sent'),
						( 'appointment_mail_sent', 'admin', 'Appointment mail send successfully', 'Appointment mail send successfully'),
						( 'select_icon', 'admin', 'Select Icon', 'Select Icon'),
						( 'select_icon_from_icon_library', 'admin', 'Select Icon from Icon library', 'Select Icon from Icon library'),
						( 'or_add_icon_in_the_icon_field', 'admin', 'Or Add icon code in the icon field', 'Or Add icon code in the icon field'),
						( 'icon_code_can_get_from', 'admin', 'Icon code can get from', 'Icon code can get from'),
						( 'here', 'admin', 'Here', 'Here'),
						( 'those_icons_are_used_only_for_profile_vcard', 'admin', 'Those icons are used only for profile and vCard sections', 'Those icons are used only for profile and vCard sections'),
						( 'demo_user_name', 'admin', 'Demo Username', 'Demo Username'),
						( 'documentation', 'admin', 'Documentaion', 'Documentaion'),
						( 'preview', 'admin', 'Preview', 'Preview'),
						('user_demo', 'admin', 'User Demo', 'User Demo'),
						('or', 'admin', 'Or', 'Or'),
						('paytm', 'admin', 'Paytm', 'Paytm'),
						('flutterwave', 'admin', 'Flutterwave', 'Flutterwave'),
						('enable', 'admin', 'Enable', 'Enable'),
						('disabled', 'admin', 'Disabled', 'Disabled'),
						('upcoming', 'admin', 'Upcoming', 'Upcoming')") or print json_encode(array('st'=>0,'msg'=>$conn->error));

						
						
					   	$insert = $conn->query("UPDATE setting SET version=$new_version,updated_at='$date',is_update='1' WHERE id=".$row['id']);
					}



					if($row['version'] < 3.8){
						$new_version = 3.8;

						$st_1 = $conn->query('CREATE TABLE `payment_method_list` (
						  `id` int(11) NOT NULL AUTO_INCREMENT,
						  `name` varchar(255) NULL,
						  `slug` varchar(255) NULL,
						  `active_slug` varchar(255) NULL,
						  `status_slug` varchar(255) NULL,
						  `status` int(11) NOT NULL DEFAULT 1,
						  PRIMARY KEY (`id`)
						) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;') or print json_encode(array('st'=>0,'msg'=>$conn->error));


						$st_1 = $conn->query("INSERT INTO `payment_method_list` (`id`, `name`, `slug`, `active_slug`, `status_slug`, `status`) VALUES
								(1, 'Paypal', 'paypal', 'paypal_status', 'is_paypal', 1),
								(2, 'Stripe', 'stripe', 'stripe_status', 'is_stripe', 1),
								(3, 'Razorpay', 'razorpay', 'razorpay_status', 'is_razorpay', 1),
								(4, 'Stripe FPX', 'stripe_fpx', 'stripe_fpx_status', 'is_fpx', 0),
								(5, 'Paytm', 'paytm', 'paytm_status', 'is_paytm', 1),
								(6, 'Mercadopago', 'mercado', 'mercado_status', 'is_mercado', 1),
								(7, 'Flutterwave', 'flutterwave', 'flutterwave_status', 'is_flutterwave', 0);") or print json_encode(array('st'=>0,'msg'=>$conn->error));


						$st_1 = $conn->query('ALTER TABLE setting ADD (is_paytm INT(11) NOT NULL, paytm_config longtext NULL, is_mercado INT(11) NOT NULL, mercado_config longtext NULL )') or print json_encode(array('st'=>0,'msg'=>$conn->error));


						$st_1 = $conn->query('ALTER TABLE setting ADD (paypal_status INT(11) NOT NULL DEFAULT 1, stripe_status INT(11) NOT NULL DEFAULT 1, razorpay_status INT(11) NOT NULL DEFAULT 1,paytm_status INT(11) NOT NULL DEFAULT 0,mercado_status INT(11) NOT NULL DEFAULT 0)') or print json_encode(array('st'=>0,'msg'=>$conn->error));
						

						$st_1 = $conn->query('ALTER TABLE payment_info  MODIFY 	payment_type VARCHAR(255) NULL') or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query('ALTER TABLE payment_info ADD (all_info JSON  NULL)') or print json_encode(array('st'=>0,'msg'=>$conn->error));





						$st_1 = $conn->query("INSERT INTO language_data(keyword,type,details,english) VALUES 
						('uninstall', 'admin', 'Uninstall', 'Uninstall'),
						('mercado', 'admin', 'Mercado', 'Mercado'),
						('mercadopago', 'admin', 'Mercadopago', 'Mercadopago')") or print json_encode(array('st'=>0,'msg'=>$conn->error));

						
						
					   	$insert = $conn->query("UPDATE setting SET version=$new_version,updated_at='$date',is_update='1' WHERE id=".$row['id']);
					}


					if($row['version'] < 3.9){
						$new_version = 3.9;


						$result = $conn->query("SHOW COLUMNS FROM setting LIKE 'is_vcard_theme'");
						$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
						if(!isset($row['Field'])){
							$conn->query('ALTER TABLE setting ADD (is_vcard_theme INT(11) NOT NULL DEFAULT 1)') or print json_encode(array('st'=>0,'msg'=>$conn->error));
						}

						$st_1 = $conn->query('ALTER TABLE setting ADD (is_share INT(11) NOT NULL DEFAULT 0)') or print json_encode(array('st'=>0,'msg'=>$conn->error));
						$st_1 = $conn->query('ALTER TABLE setting ADD (is_coupon INT(11) NOT NULL DEFAULT 0)') or print json_encode(array('st'=>0,'msg'=>$conn->error));
						$st_1 = $conn->query('ALTER TABLE user_settings ADD (is_share INT(11) NOT NULL DEFAULT 0, `share_this_key` TEXT NULL)') or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query('ALTER TABLE setting ADD (is_pwa INT(11) NOT NULL DEFAULT 0)') or print json_encode(array('st'=>0,'msg'=>$conn->error));


						$st_1 = $conn->query('ALTER TABLE setting ADD (pwa_config longtext NULL)') or print json_encode(array('st'=>0,'msg'=>$conn->error));
						
						$st_1 = $conn->query('ALTER TABLE user_settings ADD (pwa_config longtext NULL)') or print json_encode(array('st'=>0,'msg'=>$conn->error));
						
						$st_1 = $conn->query('ALTER TABLE users ADD (is_pwa INT(11) NOT NULL DEFAULT 1)') or print json_encode(array('st'=>0,'msg'=>$conn->error));




						$st_1 = $conn->query('CREATE TABLE `coupon_list` (
						  `id` int(11) NOT NULL,
						  `coupon_code` varchar(255) NOT NULL,
						  `discount` double NOT NULL,
						  `total_limit` int(11) NOT NULL,
						  `total_used` int(11) NOT NULL,
						  `created_at` datetime NOT NULL,
						  `start_date` date DEFAULT NULL,
						  `end_date` date DEFAULT NULL,
						  `status` int(11) NOT NULL DEFAULT 1,
						  PRIMARY KEY (`id`)
						) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;') or print json_encode(array('st'=>0,'msg'=>$conn->error));
						
						

						$st_1 = $conn->query("INSERT INTO language_data(keyword,type,details,english) VALUES 

						( 'uninstall', 'admin', 'Uninstall', 'Uninstall'),
						( 'paypal_payment', 'admin', 'Paypal Payment', 'Paypal Payment'),
						( 'stripe_payment_gateway', 'admin', 'Stripe Payment', 'Stripe Payment'),
						( 'discount', 'admin', 'Discount', 'Discount'),
						( 'grand_total', 'admin', 'Grand Total', 'Grand Total'),
						( 'apply', 'admin', 'Apply', 'Apply'),
						( 'coupon_code', 'admin', 'Coupon Code', 'Coupon Code'),
						( 'add_coupon', 'admin', 'Add Coupon', 'Add Coupon'),
						( 'generate_code', 'admin', 'Generate Code', 'Generate Code'),
						( 'start_date', 'admin', 'Start Date', 'Start Date'),
						( 'end_date', 'admin', 'End Date', 'End Date'),
						( 'coupon_list', 'admin', 'Coupon List', 'Coupon List'),
						( 'used', 'admin', 'Used', 'used'),
						( 'coupon_code_reached_the_max_limit', 'admin', 'Coupon code reached the maximum limit', 'Coupon code reached the maximum limit'),
						( 'coupon_code_not_exists', 'admin', 'Coupon code not exists', 'Coupon code not exists'),
						( 'select_payment_gateway', 'admin', 'Select a payment gateway', 'Select a payment gateway'),
						( 'new', 'admin', 'New', 'New'),
						( 'share_this_key', 'admin', 'ShareThis Key', 'ShareThis Key'),
						( 'show_share_button', 'admin', 'Show share button', 'Show share button'),
						( 'disable', 'admin', 'Disable', 'Disable'),
						( 'pwa', 'admin', 'PWA', 'PWA'),
						( 'background_color', 'admin', 'Background Color', 'Background Color'),
						( 'add_to_home_screen', 'admin', 'Add to home screen', 'Add to home screen');
						") or print json_encode(array('st'=>0,'msg'=>$conn->error));

						
						
					   	$insert = $conn->query("UPDATE setting SET version=$new_version,updated_at='$date',is_update='1' WHERE id=".$row['id']);
					}


					if($row['version'] < 4.0){
						$new_version = 4.0;

						$result = $conn->query("SELECT *FROM features WHERE slug ='pwa'");
						$features = mysqli_fetch_array($result, MYSQLI_ASSOC);
						
						if(!isset($features['slug'])){
							$conn->query('INSERT INTO features(features,slug,status) VALUES ("PWA","pwa",1)') or print json_encode(array('st'=>0,'msg'=>$conn->error));
						}

						$st_1 = $conn->query('ALTER TABLE users ADD (ref_id INT(11) NOT NULL DEFAULT 0)') or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query('ALTER TABLE users ADD (vcard_header_style INT(11) NOT NULL DEFAULT 1)') or print json_encode(array('st'=>0,'msg'=>$conn->error));
						
						$st_1 = $conn->query('ALTER TABLE users ADD (pwa_config longtext NULL)') or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query('ALTER TABLE users ADD (about_me_short text NULL,about_me_long longtext NULL)') or print json_encode(array('st'=>0,'msg'=>$conn->error));
						
						$st_1 = $conn->query('ALTER TABLE features_type ADD (card_limit int NOT NULL DEFAULT 1)') or print json_encode(array('st'=>0,'msg'=>$conn->error));
						
						$st_1 = $conn->query('ALTER TABLE setting ADD (about_us longtext  NULL)') or print json_encode(array('st'=>0,'msg'=>$conn->error));

						

						$st_1 = $conn->query("INSERT INTO language_data(keyword,type,details,english) VALUES 

						('size','admin','Size','Size'),
						('available_vcard','admin','Available vCard','Available vCard'),
						('icon_color_picker','admin','Icon color','Icon color'),
						('vcard_menu_style','admin','vCard Menu Style','vCard Menu Style'),
						('choose_layouts','admin','Choose layouts','Choose layouts'),
						('choose_icons','admin','Choose Icons','Choose Icons'),
						('add_vcard_icon','admin','Add vCard Social Icon','Add vCard Social Icon'),
						('about_me_long','admin','About Detailed','About Detailed'),
						('vcard_info','admin','vCard Information','vCard Information'),
						('choose_your_unique_link','admin','Choose Your Unique Link','Choose Your Unique Link'),
						('config_pwa','admin','Config PWA','Config PWA'),
						('change_layouts','admin','Change Layouts','Change Layouts'),
						('edit_add_icon','admin','Edit / Add Icon','Edit / Add Icon'),
						('edit_add_information','admin','Edit / Add Information','Edit / Add Information'),
						('vcards','admin','vCards','vCards'),
						('0_define_as_unlimited','admin','0 Define as Unlimited','0 Define as Unlimited'),
						('save_and_preview','admin','Save & Preview','Save & Preview'),
						('value_url','admin','Value / Url','Value / Url'),
						('label_title','admin','Label / Title','Label / Title'),
						('previous','admin','Previous','Previous'),
						('next','admin','Next','Next'),
						('create_a_new_vcard','admin','Create a New Vcard','Create a New Vcard'),
						('vcard_limit','admin','vCard Limit','vCard Limit'),
						('vcard_layouts','admin','vCard Layouts','vCard Layouts'),
						('configuration','admin','Configuration','Configuration');
						") or print json_encode(array('st'=>0,'msg'=>$conn->error));

						
						
					   	$insert = $conn->query("UPDATE setting SET version=$new_version,updated_at='$date',is_update='1' WHERE id=".$row['id']);
					}

					if($row['version'] < 4.1){
						$new_version = 4.1;

						$st_1 = $conn->query('ALTER TABLE user_settings ADD (vcard_settings longtext NULL)') or print json_encode(array('st'=>0,'msg'=>$conn->error));
						
						$st_1 = $conn->query('ALTER TABLE setting ADD (flutterwave_status INT(11) NOT NULL DEFAULT 0,flutterwave_config longtext NULL,is_flutterwave INT(11) NOT NULL DEFAULT 0)') or print json_encode(array('st'=>0,'msg'=>$conn->error));


						$st_1 = $conn->query('ALTER TABLE service_settings ADD (pay_button_status INT(11) NOT NULL DEFAULT 1)') or print json_encode(array('st'=>0,'msg'=>$conn->error));
						
						$st_1 = $conn->query("UPDATE payment_method_list SET status=1 WHERE id=7") or print json_encode(array('st'=>0,'msg'=>$conn->error));

						$st_1 = $conn->query("INSERT INTO language_data(keyword,type,details,english) VALUES 
						('pay_button_status','admin','Pay button status','Pay button status'),
						('show','admin','Show','Show'),
						('turn_on_vcard_click','admin','Turn On vCard button click','Turn On vCard button click'),
						('hide_vcard_value','admin','Hide vCard values','Hide vCard values');
						") or print json_encode(array('st'=>0,'msg'=>$conn->error));

						
						
					   	$insert = $conn->query("UPDATE setting SET version=$new_version,updated_at='$date',is_update='1' WHERE id=".$row['id']);
					}

					if($row['version'] < 4.2){
						$new_version = 4.2;
						$st_1 = $conn->query("INSERT INTO language_data(keyword,type,details,english) VALUES 
						('google_font_name','admin','Google Font Name','Google Font Name'),
						('custom_js','admin','Custom Js','Custom Js'),
						('custom_css','admin','Custom CSS','Custom CSS'),
						('extras','admin','Extras','Extras'),
						('change_domain','admin','Change Domain','Change Domain');
						") or print json_encode(array('st'=>0,'msg'=>$conn->error));


						$st_1 = $conn->query('ALTER TABLE setting ADD (custom_css LONGTEXT NULL ,custom_js longtext NULL,g_font_name text null)') or print json_encode(array('st'=>0,'msg'=>$conn->error));



					   	$insert = $conn->query("UPDATE setting SET version=$new_version,updated_at='$date',is_update='1' WHERE id=".$row['id']);
					}

					if($row['version'] < 4.3){
						$new_version = 4.3;

					   	$insert = $conn->query("UPDATE setting SET version=$new_version,updated_at='$date',is_update='1' WHERE id=".$row['id']);
					}

					return ['st'=>true,'msg'=>'Update Successfull'];
				} //end while
			else:
				$msg = "Sorry ".$data['database']." setting table not EXISTS";
				return ['st'=>false,'msg'=>$msg];
			endif;

	} //end function

}// end class