<?php
$pref='wpf5gdpr-';

if(isset($_POST['defdbrtext']))
{
	update_option($pref.'dbr-message',wpfresh5_gdprEditorText('databreach'));
}

if(isset($_POST['dbrsaveit']))
{
update_option($pref.'dbr-title',$_POST['dbrtitle']);
update_option($pref.'dbr-message',stripslashes($_POST['dbrmessage']));
update_option($pref.'dbr-user',$_POST['dbruser']);
}
if(isset($_POST['dbrsendmail']))
{
	$wpcrmailheaders = "MIME-Version: 1.0" . "\r\n";
    $wpcrmailheaders .= "Content-type:text/html;charset=UTF-8" . "\r\n";
	$count=0;

	$args = array('orderby' => 'display_name');
$wp_user_query = new WP_User_Query($args);
$authors = $wp_user_query->get_results();
foreach ($authors as $author) {
		$author_info = get_userdata($author->ID);
	if(wp_mail($author_info->user_email,get_option($pref.'dbr-title'),get_option($pref.'dbr-message'),$wpcrmailheaders))
	{$count++;}
}
if($count !=0)
{
	echo "<script>alert('Mail sent');</script>";
}
else
	{
	echo "<script>alert('Unable to send mail');</script>";
}
}
?>
	<?php

	if(isset($_POST['dbrshowusers']) && get_option($pref.'dbr-user')=='1')
      {
	$args = array('orderby' => 'display_name');
$wp_user_query = new WP_User_Query($args);
$authors = $wp_user_query->get_results();
if (!empty($authors)) {
	echo '<br></br><ul class="list-group">
	      <li class="list-group-item active headerLi"><h4 class="m0">Emails</h4> </li>
	';

	foreach ($authors as $author) {
		$author_info = get_userdata($author->ID);
		echo '<li class="list-group-item">' . $author_info->user_email . '</li>';
	}
	 echo '<li class="list-group-item info"><div style="text-align:center"><form action="" method="post"><button type="submit" class="btm btn-primary dbrnotibutton" name="dbrsendmail" style="border:0px;border-radius:5px;padding:6px"></button></form></div></li>';
	echo '</ul>';
} else {
	echo 'No results';
}

      }

	?>

	<?php
	if(! isset($_POST['dbrshowusers']) || get_option($pref.'dbr-user')!='1')
	{
	?>

<h3>Data Breach Notification Settings - <a href="https://wpfreshstart5.com/support/knowledgebase/data-breach/" target="_blank" style="font-size:0.8em">Support</a></h3>

    <label for="">Mail Subject:</label>
    <input class="form-control" type="text" name="dbrtitle" value="<?php echo get_option($pref.'dbr-title'); ?>">
    <label for="">Content:</label>
    <?php wp_editor(get_option($pref.'dbr-message'),"dbrmessage",$settings = array(
    'editor_height' => 200,
    'textarea_rows' => 20,
	));?>
	<br/>
		<button type="button" class="button button-secondary" id="dbreach-default-txt" >Use Default Content</button>
		<textarea  id="dbreach-def" style="display:none">Hello,<br/><br/>
We regret to inform you that there was a data breach on our site and your information or passwords may be compromised.<br/><br/>
We request you to change your password on our site asap, and also any other sites where you may have used the same password.<br/><br/>
Please also review your information with us and ensure that you are adequately protected against any misuse.<br/><br/>
We are working to fix the breach and you’ll be notified of further developments if any.<br/><br/><br/>
Thanks</textarea>
	<br/>
	<br/>
  	<label>Collect Emails From Data?</label><br>
		<label class="radio-inline"><input type="radio" style="margin-top: 2px" value="1" name="dbruser" <?php if(get_option($pref.'dbr-user')=='1'){echo 'checked';} ?> >Yes</label>
			<label class="radio-inline"><input type="radio" style="margin-top: 2px" value="0" name="dbruser" <?php if(get_option($pref.'dbr-user')=='0'){echo 'checked';} ?>>No</label><br/><br/>
<input type="hidden" class="btnsave" value="1" name="dbrsaveit">
<!-- <button type="submit" name="dbrshowusers" class="btn btn-primary dbrnotibutton"></button> -->
	<?php } ?>