<?php 

function software_set_up_cb() {
	global $post_meta;
	global $theme;
	$theme->set_themes();
	$themeOpt = array();
	if(_count($theme->themes)) {
		foreach ($theme->themes as $key => $theme_name) {
			$themeOpt[ucwords(str_replace('_', ' ', $theme_name))] = $theme_name;
		}
	}
	$company_phone = ($option = get_option('company_phone')) ? implode(',', $option) : '';
	$company_website = ($option = get_option('company_website')) ? $option : '';
	$primary_color = ($option = get_option('primary_color')) ? $option : "#337ab7";
	$secondary_color = ($option = get_option('secondary_color')) ? $option : "#1a2226";
	$smtp_username = ($option = get_option('smtp_username')) ? $option : 'apikey';
	$smtp_password = ($option = get_option('smtp_password')) ? $option : '';
	$smtp_host = ($option = get_option('smtp_host')) ? $option : 'smtp.sendgrid.net';
	$smtp_port = ($option = get_option('smtp_port')) ? $option : 465;
	$smtp_email = ($option = get_option('smtp_email')) ? $option : get_option('company_email');
	$smtp_name = ($option = get_option('smtp_name')) ? $option : get_option('company_name');
	$email_template_id = ($option = get_option('email_template_id')) ? $option : "";
	$footer_text = ($option = get_option('footer_text')) ? $option : 'Designed by Koweb Technology';
	$footer_link = ($option = get_option('footer_link')) ? $option : 'https://koweb.com.ng/';
	$role_names = ($option = get_option('role_names')) ? implode('&#13;&#10;', $option) : '';
	$exempt_users = ($option = get_option('exempt_users')) ? implode(',', $option) : "software_engineer";
	$dz_default_max_files = ($option = get_option('dz_default_max_files')) ? $option : 100;
	$current_theme = ($option = get_option('current_theme')) ? $option : 'default';
	$excel_password = ($option = get_option('excel_password')) ? $option : 'init';
	$login_user = ($option = get_option("login_user")) ? $option : "Email";
	$login_pass = ($option = get_option("login_pass")) ? $option : "Password";
	$landing_page = ($option = get_option("landing_page")) ? $option : "dashboard";
	$mailer = ($option = get_option("mailer")) ? $option : 'smtp';
	$password_rules_array = [
		"Password Must Contain at least a Numeric Character" => "numeric",
		"Password Must Contain at least an Upper Case Character" => "uppercase",
		"Password Must Contain at least a Lower Case Character" => "lowercase",
		"Password Must Contain at least a Special Character" => "specialchar"
	];
	$min_password_length = ($option = get_option("min_password_length")) ? $option : 6;
	$password_rules = ($option = get_option("password_rules")) ? $option : ["numeric"];
	?>
	<div class="row">
		<div class="col-md-12">
			<div class="panel panel-custom">
			    <div class="panel-heading">
			        <h1>Software set up</h1>
			    </div>
		        <div class="panel-body instruction">
		        	<form method="post" id="form" action="app/includes/ajax.php" data-allow-enter-button="1">
		        		<div class="row">
		        			<div class="col-md-6">
		        			<?php 
		        			label("Basic Settings");
		        			input(['label' => 'Company Name', 'id' => 'company_name', 'placeholder' => 'Company Name', 'value' => get_option('company_name')]);
		        			input(['label' => 'Company Email', 'id' => 'company_email', 'placeholder' => 'Enter email address', 'type' => 'email', 'value' => get_option('company_email')]);
		        			input(['label' => 'Company Motto', 'id' => 'company_motto', 'placeholder' => 'Company Motto', 'value' => get_option('company_motto')]);
		        			input(['label' => 'Company Phone Numbers', 'id' => 'company_phone', 'hint' => 'Enter Phone numbers (Seperate with commas)', 'value' => $company_phone]);
		        			input(['label' => 'Company website', 'id' => 'company_website', 'placeholder' => 'https://example.com', 'value' => $company_website]);
		        			textarea(['label' => 'Company Address', 'id' => 'company_address', 'placeholder' => 'Company Address', 'value' => get_option('company_address')]);
		        			input(['label' => 'Primary Color', 'id' => 'primary_color', 'type' => 'color', 'value' => $primary_color]);
		        			input(['label' => 'Secondary Color', 'id' => 'secondary_color', 'type' => 'color', 'value' => $secondary_color]);
		        			input(['label' => 'Home Url', 'id' => 'home_url', 'placeholder' => 'Home Url', 'value' => get_option('home_url')]);
		        			input(['label' => 'Landing Page', 'id' => 'landing_page', 'placeholder' => 'Landing Page', 'value' => $landing_page]);
		        			input(['label' => 'Footer Text', 'id' => 'footer_text', 'placeholder' => 'Footer Text', 'value' => get_option('footer_text')]);
		        			input(['label' => 'Footer Link', 'id' => 'footer_link', 'placeholder' => 'Footer Link', 'value' => get_option('footer_link')]);
		        			input(['label' => 'Login User Label', 'id' => 'login_user', 'value' => $login_user]);
		        			input(['label' => 'Login Password Label', 'id' => 'login_pass', 'value' => $login_pass]);
		        			checkBox(['label' => 'Enable Browser Update', 'id' => 'browser_update'], get_option('browser_update'));
		        			// label("Password Rules", "h3");
		        			select(['label' => 'Password Rules', 'id' => 'password_rules', 'name' => 'password_rules[]', 'multiple' => 'multiple'], $password_rules_array, $password_rules);
		        			input(['label' => 'Min Password Length', 'id' => 'min_password_length', 'value' => $min_password_length]);
		        			select(['label' => 'Select Theme', 'id' => 'current_theme'], $themeOpt, $current_theme);
		        			input(['label' => 'Excel Password', 'id' => 'excel_password', 'value' => $excel_password, 'type' => 'password']);
		        			if(current_user_can("update_software")) :
			        			label('Database Sectioning', "h5");				                	
				                checkBox(['label' => 'Section Database', 'id' => 'section_database'], get_option('section_database'));
				                input(['label' => 'Section Field', 'id' => 'section_field', 'placeholder' => '', 'value' => get_option('section_field')]);
				                input(['label' => 'Exempt Users', 'id' => 'exempt_users', 'placeholder' => '', 'value' => $exempt_users]);
				                label('Image/Files Library', "h5");
				                input(['label' => 'Default Max Library Files', 'id' => 'dz_default_max_files', 'value' => $dz_default_max_files]);
				                checkBox(['label' => 'Authenticate Server', 'id' => 'authenticate_server'], get_option('authenticate_server'));
		        			endif;
		        			label('Customization');
		        			textarea(['label' => 'Customize Role Names', 'id' => 'role_names', 'placeholder' => 'role_key, role_name \n\r', 'type' => 'email', 'value' => $role_names]);
		        			label('Company Logo', 'h5');
							// input(['label' => 'Width', 'id' => 'logo_width', 'value' => $logo_width]);
							// input(['label' => 'Height', 'id' => 'logo_height', 'value' => $logo_height]);
							 ?>
			                <div class="row">
			                    <?php do_action('croppie_api', ['width' => apply_filters('company-logo-width', 120), 'height' => apply_filters('company-logo-height', 60), 'url' => get_option('company-logo'), 'image-name' => 'company_logo', 'enable_resize' => true]) ?>
			                </div>
			                <?php 
			                label('Company Icon', 'h5');
							// input(['label' => 'Width', 'id' => 'logo_width', 'value' => $logo_width]);
							// input(['label' => 'Height', 'id' => 'logo_height', 'value' => $logo_height]);
							 ?>
			                <div class="row">
			                    <?php do_action('croppie_api', ['width' => 200, 'height' => 200, 'url' => get_option('company-icon'), 'image-name' => 'company_icon']) ?>
			                </div>
			                <?php
		        			do_action('more_settings_field_left');
		        			 ?>
		        		</div>
		        		<div class="col-md-6">
		        			<?php
			                label('SMTP Settings');
							checkBox(['label' => 'Send Emails', 'id' => 'send_emails'], get_option('send_emails'));
							radio(['name' => 'mailer'], ['smtp' => 'SMTP', 'sendmail' => 'Sendmail', 'qmail' => 'Qmail', 'mail' => 'Mail'], $mailer);
			                input(['label' => 'SMTP Username', 'id' => 'smtp_username', 'value' => $smtp_username]);
			                input(['label' => 'SMTP Password', 'id' => 'smtp_password', 'value' => $smtp_password, 'type' => 'password']);
			                input(['label' => 'SMTP Host', 'id' => 'smtp_host', 'value' => $smtp_host]);
			                input(['label' => 'SMTP Port', 'id' => 'smtp_port', 'value' => $smtp_port]);
			                input(['label' => 'SMTP Email', 'id' => 'smtp_email', 'value' => $smtp_email]);
			                input(['label' => 'SMTP Name', 'id' => 'smtp_name', 'value' => $smtp_name]);
			                input(['label' => 'Template ID', 'id' => 'email_template_id', 'value' => $email_template_id]);
			                do_action('more_settings_field_right');
			                 ?>
		        		</div>
		        		<div class="col-md-12">
		        			<?php alert(); submit_btn('software_set_up', 'Submit'); ?>
		        		</div>
		        		</div>
		        		
		        	</form>
				</div>
			</div>
		</div>
	</div>
		
	<?php
	add_page_javascript('app/assets/js/page-scripts/koweb.js');
	add_page_javascript('app/assets/js/page-scripts/submit.js');
}