| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn { |
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Class UICategories |
| 10 |
* Show the Category and Assigned DOIs |
| 11 |
* |
| 12 |
* @package forge12\contactform7\CF7DoubleOptIn |
| 13 |
*/ |
| 14 |
class UICategoriesView extends UIPage { |
| 15 |
/** |
| 16 |
* Class constructor. |
| 17 |
* |
| 18 |
* @param TemplateHandler $templateHandler The template handler object. |
| 19 |
* @param string $domain The domain string. |
| 20 |
*/ |
| 21 |
public function __construct( TemplateHandler $templateHandler, string $domain ) { |
| 22 |
parent::__construct( $templateHandler, $domain, 'categories_view', __('Category View', 'double-opt-in') ); |
| 23 |
|
| 24 |
add_action( 'admin_init', array( $this, 'maybeUpdateCategory' ) ); |
| 25 |
} |
| 26 |
|
| 27 |
public function maybeUpdateCategory() { |
| 28 |
if ( isset( $_POST['doi_settings_nonce'] ) && ! wp_verify_nonce( $_POST['doi_settings_nonce'], 'doi_settings_action' ) ) { |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
if ( ! isset( $_POST['doubleoptin-settings-edit-submit'] ) ) { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
if ( ! isset( $_POST['category_id'] ) ) { |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
$category_id = (int) $_POST['category_id']; |
| 41 |
|
| 42 |
$Category = Category::get_by_id( $category_id ); |
| 43 |
|
| 44 |
if ( null === $Category ) { |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
$name = sanitize_text_field( $_POST['categorie_name'] ); |
| 49 |
|
| 50 |
if ( empty( $name ) ) { |
| 51 |
return false; |
| 52 |
} |
| 53 |
|
| 54 |
$Category->set_name( $name ); |
| 55 |
|
| 56 |
if ( $Category->save() ) { |
| 57 |
Messages::getInstance()->add( __( 'Category updated', 'double-opt-in' ), 'success' ); |
| 58 |
} else { |
| 59 |
Messages::getInstance()->add( __( 'Category update failed', 'double-opt-in' ), 'error' ); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Hide this page in the menu. |
| 65 |
* |
| 66 |
* @return bool |
| 67 |
*/ |
| 68 |
public function hideInMenu() { |
| 69 |
return true; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Render the license subpage content |
| 74 |
*/ |
| 75 |
protected function theContent( $slug, $page, $settings ) { |
| 76 |
/* |
| 77 |
* Ensure that the ID for the Categorie is set |
| 78 |
*/ |
| 79 |
if ( ! isset( $_GET['id'] ) ) { |
| 80 |
wp_redirect( admin_url( 'admin.php' ) . '?page=f12-cf7-doubleoptin' ); |
| 81 |
} |
| 82 |
|
| 83 |
$id = (int) $_GET['id']; |
| 84 |
|
| 85 |
/* |
| 86 |
* Load the assigned Category |
| 87 |
*/ |
| 88 |
$Category = Category::get_by_id( $id ); |
| 89 |
|
| 90 |
if ( null === $Category ) { |
| 91 |
wp_redirect( admin_url( 'admin.php' ) . '?page=f12-cf7-doubleoptin' ); |
| 92 |
} |
| 93 |
|
| 94 |
$atts = array( |
| 95 |
'perPage' => 10, |
| 96 |
'page' => 1, |
| 97 |
'order' => 'DESC', |
| 98 |
); |
| 99 |
|
| 100 |
if ( isset( $_GET['pageNum'] ) ) { |
| 101 |
$atts['page'] = (int) $_GET['pageNum']; |
| 102 |
} |
| 103 |
|
| 104 |
if ( isset( $_GET['perPage'] ) ) { |
| 105 |
$atts['perPage'] = (int) $_GET['perPage']; |
| 106 |
} |
| 107 |
|
| 108 |
if ( isset( $_GET['keyword'] ) ) { |
| 109 |
$atts['keyword'] = sanitize_text_field( $_GET['keyword'] ); |
| 110 |
} |
| 111 |
|
| 112 |
$numberOfPages = 0; |
| 113 |
$listOfOptIns = OptIn::get_list_by_category_id( $Category->get_id(), $atts, $numberOfPages ); |
| 114 |
|
| 115 |
/* |
| 116 |
* Render the Template |
| 117 |
*/ |
| 118 |
?> |
| 119 |
<h1><?php _e( 'Category: ', 'double-opt-in' ) . esc_attr_e( $Category->get_name() ); ?></h1> |
| 120 |
<?php |
| 121 |
|
| 122 |
$this->TemplateHandler->renderTemplate( 'list-optins', array( |
| 123 |
'domain' => $this->domain, |
| 124 |
'listOfOptIns' => $listOfOptIns, |
| 125 |
'numberOfPages' => $numberOfPages, |
| 126 |
'currentPage' => $atts['page'], |
| 127 |
'slug' => $slug |
| 128 |
) ); |
| 129 |
} |
| 130 |
|
| 131 |
protected function theSidebar( $slug, $page ) { |
| 132 |
/* |
| 133 |
* Ensure that the ID for the Categorie is set |
| 134 |
*/ |
| 135 |
if ( ! isset( $_GET['id'] ) ) { |
| 136 |
wp_redirect( admin_url( 'admin.php' ) . '?page=f12-cf7-doubleoptin' ); |
| 137 |
} |
| 138 |
|
| 139 |
$id = (int) $_GET['id']; |
| 140 |
|
| 141 |
/* |
| 142 |
* Load the assigned Category |
| 143 |
*/ |
| 144 |
$Category = Category::get_by_id( $id ); |
| 145 |
|
| 146 |
?> |
| 147 |
<div class="box"> |
| 148 |
<h2> |
| 149 |
<?php _e( 'Edit Category:', 'double-opt-in' ); ?> |
| 150 |
</h2> |
| 151 |
|
| 152 |
<form action="" method="post"> |
| 153 |
<div class="option"> |
| 154 |
<input type="hidden" value="<?php esc_attr_e( $_GET['id'] ); ?>" name="category_id"/> |
| 155 |
<div class="input"> |
| 156 |
<input type="text" name="categorie_name" |
| 157 |
value="<?php esc_attr_e( $Category->get_name() ); ?>" |
| 158 |
placeholder="<?php _e( 'Please enter the Name of the Categorie', 'double-opt-in' ); ?>"/> |
| 159 |
<p> |
| 160 |
<?php _e( 'Enter the name of the Categorie and submit.', 'double-opt-in' ); ?> |
| 161 |
</p> |
| 162 |
</div> |
| 163 |
</div> |
| 164 |
<?php |
| 165 |
wp_nonce_field( 'doi_settings_action', 'doi_settings_nonce' ); |
| 166 |
?> |
| 167 |
|
| 168 |
<input type="submit" name="doubleoptin-settings-edit-submit" class="button" |
| 169 |
value=" <?php _e( 'Update', 'double-opt-in' ); ?>"/> |
| 170 |
</form> |
| 171 |
</div> |
| 172 |
<?php |
| 173 |
} |
| 174 |
|
| 175 |
public function getSettings( $settings ) { |
| 176 |
return $settings; |
| 177 |
} |
| 178 |
} |
| 179 |
} |