| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn { |
| 4 |
if (!defined('ABSPATH')) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Class UIDatabase |
| 10 |
* @package forge12\contactform7\CF7DoubleOptIn |
| 11 |
*/ |
| 12 |
class UIDatabase extends UIPageForm |
| 13 |
{ |
| 14 |
public function __construct($domain) |
| 15 |
{ |
| 16 |
parent::__construct($domain, 'database', 'Database', 50); |
| 17 |
$this->hideSubmitButton(true); |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Save on form submit |
| 22 |
*/ |
| 23 |
private function maybeCleanDatabase() |
| 24 |
{ |
| 25 |
// Check if the form is posted and the nonce is valid |
| 26 |
if ((isset($_POST['doi-clean-submit']) || isset($_POST['doi-clean-confirmed-submit']) || isset($_POST['doi-clean-unconfirmed-submit']))) { |
| 27 |
$CleanUp = new CleanUp(); |
| 28 |
if (isset($_POST['doi-clean-submit']) || isset($_POST['doi-clean-confirmed-submit'])) { |
| 29 |
$CleanUp->removeConfirmedOptins(); |
| 30 |
} |
| 31 |
if (isset($_POST['doi-clean-submit']) || isset($_POST['doi-clean-unconfirmed-submit'])) { |
| 32 |
$CleanUp->removeUnconfirmedOptins(); |
| 33 |
} |
| 34 |
|
| 35 |
Messages::getInstance()->add(__('Database cleaned.', 'double-opt-in'), 'success'); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Reset the database deleting all entries. |
| 41 |
*/ |
| 42 |
private function maybeResetDatabase() |
| 43 |
{ |
| 44 |
// Check if the form is posted and the nonce is valid |
| 45 |
if (isset($_POST['doi-reset-submit'])) { |
| 46 |
$CleanUp = new CleanUp(); |
| 47 |
$CleanUp->reset(); |
| 48 |
|
| 49 |
Messages::getInstance()->add(__('Database reset finished.', 'double-opt-in'), 'success'); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Render the license subpage content |
| 55 |
*/ |
| 56 |
protected function theContent($slug, $page, $settings) |
| 57 |
{ |
| 58 |
?> |
| 59 |
<h2> |
| 60 |
<?php _e('Database', 'double-opt-in'); ?> |
| 61 |
</h2> |
| 62 |
<?php |
| 63 |
wp_nonce_field('doi_settings_action', 'doi_settings_nonce'); |
| 64 |
?> |
| 65 |
|
| 66 |
<div class="option"> |
| 67 |
<div class="label"> |
| 68 |
<label for="delete"><?php _e('Clean Database', 'double-opt-in'); ?></label> |
| 69 |
</div> |
| 70 |
<div class="input"> |
| 71 |
<input type="submit" name="doi-clean-submit" class="button" |
| 72 |
value="<?php _e('Clean All', 'double-opt-in'); ?>"/> |
| 73 |
<input type="submit" name="doi-clean-confirmed-submit" class="button" |
| 74 |
value="<?php _e('Clean Confirmed', 'double-opt-in'); ?>"/> |
| 75 |
<input type="submit" name="doi-clean-unconfirmed-submit" class="button" |
| 76 |
value="<?php _e('Clean Unconfirmed', 'double-opt-in'); ?>"/> |
| 77 |
<p> |
| 78 |
<?php _e('Make sure you backup your database before clicking one of these buttons.', 'double-opt-in'); ?> |
| 79 |
</p> |
| 80 |
</div> |
| 81 |
</div> |
| 82 |
<div class="option"> |
| 83 |
<div class="label"> |
| 84 |
<label for="delete"><?php _e('Reset Database', 'double-opt-in'); ?></label> |
| 85 |
</div> |
| 86 |
<div class="input"> |
| 87 |
<input type="submit" name="doi-reset-submit" class="button button-delete" |
| 88 |
value="<?php _e('Reset', 'double-opt-in'); ?>"/> |
| 89 |
<p> |
| 90 |
<?php _e('Make sure you backup your database before clicking one of these buttons. If you click this button, all Opt-Ins will be deleted.', 'double-opt-in'); ?> |
| 91 |
</p> |
| 92 |
</div> |
| 93 |
</div> |
| 94 |
<?php |
| 95 |
} |
| 96 |
|
| 97 |
protected function theSidebar($slug, $page) |
| 98 |
{ |
| 99 |
if ($page != 'settings') { |
| 100 |
return; |
| 101 |
} |
| 102 |
?> |
| 103 |
<div class="box"> |
| 104 |
<h2> |
| 105 |
<?php _e('Hint:', 'double-opt-in'); ?> |
| 106 |
</h2> |
| 107 |
<p> |
| 108 |
<?php _e("In the table on the left side, you'll find an list containing all Opt-Ins and the required information from your customers. Click on the hash to open aditional informations about the form and the user data. All unconfirmed opt-ins will be deleted after 7 days.", 'double-opt-in'); ?> |
| 109 |
</p> |
| 110 |
</div> |
| 111 |
<?php |
| 112 |
} |
| 113 |
|
| 114 |
public function getSettings($settings) |
| 115 |
{ |
| 116 |
return $settings; |
| 117 |
} |
| 118 |
|
| 119 |
protected function onSave($settings) |
| 120 |
{ |
| 121 |
// Check if the user wants to clean the database manually |
| 122 |
$this->maybeCleanDatabase(); |
| 123 |
// Check if the user wants to reset the database manually |
| 124 |
$this->maybeResetDatabase(); |
| 125 |
|
| 126 |
return $settings; |
| 127 |
} |
| 128 |
} |
| 129 |
} |