<?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>';

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

$breadcrummbs = array('dashboard', 'lm_config', 'lms_emailconfig');

echo get_breadcrumb($breadcrummbs);

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 my-3">
			<div class="col-sm-4">
				<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>
			</div>
			<div class="col-sm-4">
				<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>
		<div class="row mx-auto w-100 my-3 smtpmail">
			<div class="col-sm-4">
				<label class="control-label">'.__('SMTP Server').'</label>
			</div>
			<div class="col-sm-4">
				<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>
		<div class="row mx-auto w-100 my-3 smtpmail">
			<div class="col-sm-4">
				<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>
			</div>
			<div class="col-sm-4">
				<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>
		<div class="row mx-auto w-100 my-3 smtpmail">
			<div class="col-sm-4">
				<label class="control-label">'.__('SMTP Username').'</label>
			</div>
			<div class="col-sm-4">
				<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>
		<div class="row mx-auto w-100 my-3 smtpmail">
			<div class="col-sm-4">
				<label class="control-label">'.__('SMTP Password').'</label>
			</div>
			<div class="col-sm-4">
				<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>
		<div class="row mx-auto w-100 my-3 smtpmail">
			<div class="col-4">
				<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>
			<div class="col-4" id="radio_secure">
				<div class="row mx-auto w-100">
					<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>
		<div class="row mx-auto w-100 my-3 smtpmail">
			<div class="col-sm-4">
				<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>
			</div>
			<div class="col-sm-4">
				<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>
		<div class="row mx-auto w-100 my-3 smtpmail">
			<div class="col-4">
				<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-4">
				'.get_checkbox('mail_debug', '', '', array('chk_it' => 1, 'val' => $info['mail_debug'])).'
			</div>
		</div>
		<div class="row mx-auto w-100 my-3">
			<div class="col-4">
				<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-4">
				'.get_checkbox('disable_email', '', '', array('chk_it' => 1, 'val' => $info['disable_email'])).'
			</div>
		</div>
		<br/>
		<p align="center"><input type="submit" name="editemailconfigsettings" value="'.__('Edit Settings').'" class="go_btn"/></p>
	</form>';
}
echo'
</div>';

softfooter();

}
