PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/dashboard/admin_panel.php

https://gitlab.com/itinarraylab/ongage-custom-sender
PHP | 345 lines | 270 code | 69 blank | 6 comment | 16 complexity | 4fa19e0482d9063892bec36326a6dee4 MD5 | raw file
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: const
  5. * Date: 2016-10-14
  6. * Time: 1:13 PM
  7. */
  8. add_action('admin_menu', 'ongage_admin_menu');
  9. function ongage_admin_menu()
  10. {
  11. add_options_page(
  12. __('Ongage Settings', 'wpongage'),
  13. __('Ongage Settings', 'wpongage'),
  14. 'manage_options',
  15. 'wpongage',
  16. 'ongage_show_options_page'
  17. );
  18. }
  19. function ongage_show_options_page()
  20. {
  21. if (!current_user_can('manage_options'))
  22. wp_die(__('You do not have sufficient permissions to access this page.'));
  23. $test_result = "";$test_subscribe_result="";
  24. if (count($_POST) > 0 && isset($_POST['onage_settings'])) {
  25. $prefix = 'ongage_';
  26. $options = ['ongage'];
  27. foreach ($options as $opt) {
  28. delete_option($prefix . $opt);
  29. if (isset($_POST[$opt]))
  30. add_option($prefix . $opt, $_POST[$opt]);
  31. }
  32. }
  33. if (count($_POST) > 0 && isset($_POST['ongage_send_test'])) {
  34. $email = ongage_get_test_email();
  35. if ($email) {
  36. $test_result = ongageCustomPlugin::sendTest('const.ca@gmail.com');
  37. } else {
  38. $test_result = 'Email cannot be empty value';
  39. }
  40. }
  41. if (count($_POST) > 0 && isset($_POST['ongage_send_subscribe_test'])) {
  42. $email = ongage_get_test_subscribe_email();
  43. $fname = ongage_get_test_subscribe_fname();
  44. $lname= ongage_get_test_subscribe_lname();
  45. if ($email!='' && $fname!='' && $lname!='') {
  46. $result = ongageCustomPlugin::subscribe($email, $fname, $lname, true);
  47. $test_subscribe_result = json_encode($result);
  48. } else {
  49. $test_subscribe_result = 'All Fields Are Mandatory';
  50. }
  51. }
  52. ?>
  53. <style>
  54. .button-secondary {
  55. background: #ff0000 !important;
  56. color: #ffffff !important;
  57. }
  58. .message_test {
  59. min-height: 50px;
  60. width: 100%
  61. }
  62. </style>
  63. <div class="wrap">
  64. <h1>Ongage Settings</h1>
  65. <form method="post">
  66. <fieldset>
  67. <legend><strong>Ongage Account Settings</strong></legend>
  68. <table class="form-table">
  69. <tr>
  70. <th><label for="ongage_account_code">Account Code</label></th>
  71. <td>
  72. <input name="ongage[account_code]" type="text" id="ongage_account_code"
  73. value="<?= ongage_get_array_option('ongage', 'account_code') ?>"
  74. class="regular-text" placeholder="Enter Ongage Account Code" autocomplete="off"/>
  75. </td>
  76. </tr>
  77. <tr>
  78. <th><label for="ongage_username">Username</label></th>
  79. <td>
  80. <input name="ongage[username]" type="email" id="ongage_username"
  81. value="<?= ongage_get_array_option('ongage', 'username') ?>"
  82. class="regular-text" autocomplete="off" placeholder="Enter Ongage Username"/>
  83. </td>
  84. </tr>
  85. <tr>
  86. <th><label for="ongage_password">Password</label></th>
  87. <td>
  88. <input name="ongage[password]" type="password" id="ongage_password"
  89. value="<?= ongage_get_array_option('ongage', 'password') ?>"
  90. class="regular-text" autocomplete="off" placeholder="Enter Ongage Password"/>
  91. </td>
  92. </tr>
  93. <tr>
  94. <th><label for="ongage_esp_id">ESP ID (ESP Connection ID)</label></th>
  95. <td>
  96. <input name="ongage[esp_id]" type="text" id="ongage_esp_id"
  97. value="<?= ongage_get_array_option('ongage', 'esp_id') ?>"
  98. class="regular-text" autocomplete="off" placeholder="Enter Ongage ESP ID"/>
  99. </td>
  100. </tr>
  101. <tr>
  102. <th><label for="ongage_mailing_id">Transactional Campaign Id</label></th>
  103. <td>
  104. <input name="ongage[mailing_id]" type="text" id="ongage_mailing_id"
  105. value="<?= ongage_get_array_option('ongage', 'mailing_id') ?>"
  106. class="regular-text" autocomplete="off" placeholder="Transactional Campaigns (e.g Default Transactional Campaign Id) "/>
  107. </td>
  108. </tr>
  109. <tr>
  110. <th><label for="ongage_list_id">List Id</label></th>
  111. <td>
  112. <input name="ongage[list_id]" type="text" id="ongage_list_id"
  113. value="<?= ongage_get_array_option('ongage', 'list_id') ?>"
  114. class="regular-text" autocomplete="off" placeholder="List Id"/>
  115. </td>
  116. </tr>
  117. </table>
  118. </fieldset>
  119. <fieldset>
  120. <legend><strong>Sender Settings: </strong></legend>
  121. <table class="form-table">
  122. <tr>
  123. <th><label for="ongage_from_name">FROM Name</label></th>
  124. <td>
  125. <input name="ongage[from_name]" type="text" id="ongage_from_name"
  126. value="<?= ongage_get_array_option('ongage', 'from_name') ?>"
  127. class="regular-text" autocomplete="off" placeholder="Name From"/>
  128. </td>
  129. </tr>
  130. <tr>
  131. <th><label for="ongage_from_address">FROM Email</label></th>
  132. <td>
  133. <input name="ongage[from_address]" type="email" id="ongage_from_address"
  134. value="<?= ongage_get_array_option('ongage', 'from_address') ?>"
  135. class="regular-text" autocomplete="off" placeholder="Email Address From"/>
  136. </td>
  137. </tr>
  138. <tr>
  139. <th><label for="ongage_reply_address">Reply-To Email</label></th>
  140. <td>
  141. <input name="ongage[reply_address]" type="email" id="ongage_reply_address"
  142. value="<?= ongage_get_array_option('ongage', 'reply_address') ?>"
  143. class="regular-text" autocomplete="off" placeholder="Email Address Reply"/>
  144. </td>
  145. </tr>
  146. </table>
  147. </fieldset>
  148. <fieldset>
  149. <legend><strong>User Registration: </strong></legend>
  150. <table class="form-table">
  151. <tr valign="top">
  152. <th scope="row"><label for="ongage_subscribe_mode">Subscribe New Users</label></th>
  153. <td>
  154. <input name="ongage[subscribe_mode]" type="checkbox" id="ongage_subscribe_mode"
  155. <?php echo ongage_get_array_checkbox_option('ongage', 'subscribe_mode'); ?>
  156. />
  157. Check this to subscribe new users to email list.
  158. </td>
  159. </tr>
  160. </table>
  161. </fieldset>
  162. <fieldset>
  163. <legend><strong>Developer Tools: </strong></legend>
  164. <table class="form-table">
  165. <tr valign="top">
  166. <th scope="row"><label for="ongage_debug_mode">Debug Mode</label></th>
  167. <td>
  168. <input name="ongage[debug_mode]" type="checkbox" id="ongage_debug_mode"
  169. <?php echo ongage_get_array_checkbox_option('ongage', 'debug_mode'); ?>
  170. />
  171. Check this to enable debug mode. (Output sends to error log)
  172. </td>
  173. </tr>
  174. </table>
  175. </fieldset>
  176. <?= ongage_print_button('Save Changes'); ?>
  177. </form>
  178. <fieldset id="test_box">
  179. <form method="post" action="#test_box">
  180. <table class="form-table">
  181. <tr>
  182. <th><label for="ongage_test_email">Test Email</label></th>
  183. <td>
  184. <input name="ongage_test_email" type="email" id="ongage_test_email"
  185. value="<?= ongage_get_test_email() ?>"
  186. class="regular-text" autocomplete="off" placeholder="Add Your Email To Receive a Test"/>
  187. </td>
  188. </tr>
  189. </table>
  190. <?= ongage_print_button('Send Test Email', 'ongage_send_test', 'button-secondary'); ?>
  191. <div class="message_test">
  192. <p>
  193. <?= $test_result; ?>
  194. </p>
  195. </div>
  196. </form>
  197. </fieldset>
  198. <fieldset id="test_subscribe_box">
  199. <form method="post" action="#test_subscribe_box">
  200. <table class="form-table">
  201. <tr>
  202. <th><label for="ongage_test_subscribe_email">Test Subscribe Email</label></th>
  203. <td>
  204. <input name="ongage_test_subscribe_email" type="email" id="ongage_test_subscribe_email"
  205. value="<?= ongage_get_test_subscribe_email() ?>"
  206. class="regular-text" autocomplete="off" placeholder="Add New Email To Test Subscription"/>
  207. </td>
  208. </tr>
  209. <tr>
  210. <th><label for="ongage_test_subscribe_fname">Test Subscribe First Name</label></th>
  211. <td>
  212. <input name="ongage_test_subscribe_fname" type="text" id="ongage_test_subscribe_fname"
  213. value="<?= ongage_get_test_subscribe_fname() ?>"
  214. class="regular-text" autocomplete="off" placeholder="Add New First Name To Test Subscription"/>
  215. </td>
  216. </tr>
  217. <tr>
  218. <th><label for="ongage_test_subscribe_lname">Test Subscribe Last Name</label></th>
  219. <td>
  220. <input name="ongage_test_subscribe_lname" type="text" id="ongage_test_subscribe_lname"
  221. value="<?= ongage_get_test_subscribe_lname() ?>"
  222. class="regular-text" autocomplete="off" placeholder="Add New Last Name To Test Subscription"/>
  223. </td>
  224. </tr>
  225. </table>
  226. <?= ongage_print_button('Subscribe Test Email', 'ongage_send_subscribe_test', 'button-secondary'); ?>
  227. <div class="message_test">
  228. <p>
  229. <?= $test_subscribe_result; ?>
  230. </p>
  231. </div>
  232. </form>
  233. </fieldset>
  234. </div>
  235. <?php
  236. }
  237. function ongage_get_array_option($key, $value, $prefix = 'ongage_')
  238. {
  239. $key = $prefix . $key;
  240. return isset(get_option($key)[$value]) ? get_option($key)[$value] : '';
  241. }
  242. function ongage_get_array_checkbox_option($key, $value, $prefix = 'ongage_')
  243. {
  244. $key = $prefix . $key;
  245. return isset(get_option($key)[$value]) ? (get_option($key)[$value] == 'on') ? 'checked' : '' : '';
  246. }
  247. function ongage_print_button($value, $hidden_name='onage_settings', $btn_class='button-primary')
  248. {
  249. $btn = "<p class=\"submit\">" . PHP_EOL;
  250. $btn .= "<input type=\"submit\" name=\"Submit\" class=\"button $btn_class\" value=\"$value\" />" . PHP_EOL;
  251. $btn .= "<input type=\"hidden\" name=\"$hidden_name\" value=\"save\" style=\"display:none;\" />" . PHP_EOL;
  252. $btn .= "</p>" . PHP_EOL;
  253. return $btn;
  254. }
  255. function ongage_get_test_email()
  256. {
  257. return isset($_POST['ongage_test_email']) ? $_POST['ongage_test_email'] : '';
  258. }
  259. function ongage_get_test_subscribe_email()
  260. {
  261. return isset($_POST['ongage_test_subscribe_email']) ? $_POST['ongage_test_subscribe_email'] : '';
  262. }
  263. function ongage_get_test_subscribe_fname()
  264. {
  265. return isset($_POST['ongage_test_subscribe_fname']) ? $_POST['ongage_test_subscribe_fname'] : '';
  266. }
  267. function ongage_get_test_subscribe_lname()
  268. {
  269. return isset($_POST['ongage_test_subscribe_lname']) ? $_POST['ongage_test_subscribe_lname'] : '';
  270. }
  271. function print_test_result($result = null)
  272. {
  273. if (!is_null($result)) {
  274. return $result;
  275. }
  276. }