<?php

//////////////////////////////////////////////////////////////
//===========================================================
// emailconfig_theme.php
//===========================================================
// SOFTACULOUS 
// Version : 1.1
// Inspired by the DESIRE to be the BEST OF ALL
// ----------------------------------------------------------
// Started by: Alons
// Date:       10th Jan 2009
// Time:       21:00 hrs
// Site:       http://www.softaculous.com/ (SOFTACULOUS)
// ----------------------------------------------------------
// Please Read the Terms of use at http://www.softaculous.com
// ----------------------------------------------------------
//===========================================================
// (c)Softaculous Inc.
//===========================================================
//////////////////////////////////////////////////////////////

if(!defined('VIRTUALIZOR')){

	die('Hacking Attempt');

}

function emailconfig_theme(){

global $theme, $l, $globals, $cluster, $langs, $skins, $error, $saved , $done, $info;

softheader($l['<title>']);
					
echo '
<script type="text/javascript">

	$(document).ready(function(){	
		change_email_opt();
	});

	function change_email_opt(){
		var val = $("#mail_type option:selected").attr("value");
		$(".smtpmail").css("display", "none");
		if(val == 0){
			$(".smtpmail").show();
		}
	}

</script>';


$GLOBALS['breadcrumbs'] = array('dashboard', 'lm_emailconfig', 'lms_emailconfig');

echo page_header(__('Email Settings'), 'fas fa-wrench', $globals['docs'].'configure-email-settings/', 0, 0, '');

error_handle($error, '100%');

if(!empty($done)){
	show_alert(__('The Email Settings has been changed.'));
}

// Is it offline ?
$hypervisor_status = $cluster->statewise($globals['server']);
if($hypervisor_status == 0 || $hypervisor_status == 2){
	show_alert($globals['hypervisor_status'][$hypervisor_status],"1");
	echo '<div class="e_notice"><b>'.__('Note').' : </b> &nbsp; '.$globals['hypervisor_status'][$hypervisor_status].'</div>';
	
}else{


echo '
<div id="form-container" class="card p-2 mx-3">
	<form accept-charset="'.$globals['charset'].'" name="editemailconfigsettings" method="post" action="" class="form-horizontal">
		<div class="row mx-auto w-100 mt-2">
			<div class="col-sm-6">
				<label class="control-label">'.__('Mailing Method').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Send mail using PHP mail() function or your SMTP server').'"><i class="fas text-primary fa-info-circle"></i></a></label>
				<select class="custom-select" name="mail" onchange="change_email_opt();" id="mail_type">
					<option value="1" '.(POSTval('mail') == '1' ? 'selected="selected"' : ($info['mail'] == 1 ? 'selected="selected"' : '')).'>PHP Mail</option>
					<option value="0" '.(POSTval('mail') == '0' ? 'selected="selected"' : ($info['mail'] == 0 ? 'selected="selected"' : '')).'>SMTP</option>
				</select>
			</div>
			<div class="col-sm-6 smtpmail">
				<label class="control-label">'.__('SMTP Server').'</label>
				<input type="text" class="form-control" name="mail_server" size="30" value="'.POSTval('mail_server', $info['mail_server']).'" />
				<span class="help-block"></span>
			</div>
			<div class="col-sm-6 mt-2 smtpmail">
				<label class="control-label">'.__('SMTP Port').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('If port 465 does not work, then use port 587').'"><i class="fas text-primary fa-info-circle"></i></a></label>
				<input type="number" min="0" class="form-control" name="mail_port" size="30" value="'.POSTval('mail_port', $info['mail_port']).'" />
				<span class="help-block"></span>
			</div>
			<div class="col-sm-6 mt-2 smtpmail">
				<label class="control-label">'.__('SMTP Username').'</label>
				<input type="text" class="form-control" name="mail_user" size="30" value="'.POSTval('mail_user', $info['mail_user']).'" />
				<span class="help-block"></span>
			</div>
			<div class="col-sm-6 mt-2 smtpmail">
				<label class="control-label">'.__('SMTP Password').'</label>
				<input type="password" class="form-control" name="mail_pass" size="30" value="'.POSTval('mail_pass', $info['mail_pass']).'" />
				<span class="help-block"></span>
			</div>
			<div class="col-sm-6 mt-2 smtpmail">
				<label class="control-label">'.__('Secure connection').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Securely Connect to mail server using the selected mode.').'"><i class="fas text-primary fa-info-circle"></i></a></label>
				<div class="row mx-auto w-100" id="radio_secure">
					<div class="col-4 p-0">
						<label class="custom-control custom-radio">
							<input type="radio" class="custom-control-input" id="secure_none" value="0" name="mail_smtp_secure" '.POSTradio('mail_smtp_secure', 0, $info['mail_smtp_secure']).'>
							<span class="custom-control-label" for="secure_none">'.__('None').'</span>
						</label> 
					</div>
					<div class="col-4 p-0">
						<label class="custom-control custom-radio">
							<input type="radio" class="custom-control-input" id="secure_ssl" value="1" name="mail_smtp_secure" '.POSTradio('mail_smtp_secure', 1, $info['mail_smtp_secure']).'>
							<span class="custom-control-label" for="secure_ssl">'.__('SSL').'</span>
						</label>
					</div>
					<div class="col-4 p-0">
						<label class="custom-control custom-radio">
							<input type="radio" class="custom-control-input" id="secure_starttls" value="2" name="mail_smtp_secure" '.POSTradio('mail_smtp_secure', 2, $info['mail_smtp_secure']).'>
							<span class="custom-control-label" for="secure_starttls">'.__('STARTTLS').'</span>
						</label>
					</div>	
				</div>		
			</div>
			<div class="col-sm-6 mt-2 smtpmail">
				<label class="control-label">'.__('Connection Timeout').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Connection Timeout in seconds, Virtualizor will wait for mail server\'s response for specified seconds before getting timed-out. Default is 5. Please set greater than 5 if you want to change the timeout.').'"><i class="fas text-primary fa-info-circle"></i></a></label>
				<input type="number" class="form-control" name="mail_connect_timeout" size="30" value="'.POSTval('mail_connect_timeout', $info['mail_connect_timeout']).'" />
				<span class="help-block"></span>
			</div>
			<div class="col-sm-6 mt-2 smtpmail">
				<div class="row mx-auto">
					<div class="col-sm-3 p-0">
						<label class="control-label">'.__('Enable Debugging').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Log debug output generated when sending email. Logs generated can be viewed under /var/virtualizor/log/email/email.log').'"><i class="fas text-primary fa-info-circle"></i></a></label>
					</div>
					<div class="col-sm-9 d-flex justify-content-end p-0">
						'.get_switch('mail_debug', '', '', array('chk_it' => 1, 'val' => $info['mail_debug'])).'
					</div>
				</div>
			</div>
			<div class="col-sm-6 mt-2">
				<div class="row mx-auto">
					<div class="col-sm-6 p-0">
						<label class="control-label">'.__('Disable Email').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('No email will be sent by the system').'"><i class="fas text-primary fa-info-circle"></i></a></label>
					</div>
					<div class="col-sm-6 d-flex justify-content-end p-0">
						'.get_switch('disable_email', '', '', array('chk_it' => 1, 'val' => $info['disable_email'])).'
					</div>
				</div>
			</div>
		</div>

		<br/><br/>
		<p align="center"><input type="submit" name="editemailconfigsettings" value="'.__('Save Settings').'" class="go_btn"/></p>
		<br/>
	</form>';
}
echo'
</div>';

softfooter();

}
