index.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit;
  4. }
  5. @include_once NEWSLETTER_INCLUDES_DIR . '/controls.php';
  6. $controls = new NewsletterControls();
  7. wp_enqueue_script( 'tnp-chart' );
  8. if ( $controls->is_action( 'feed_enable' ) ) {
  9. delete_option( 'newsletter_feed_demo_disable' );
  10. $controls->messages = 'Feed by Mail demo panels enabled. On next page reload it will show up.';
  11. }
  12. if ( $controls->is_action( 'feed_disable' ) ) {
  13. update_option( 'newsletter_feed_demo_disable', 1 );
  14. $controls->messages = 'Feed by Mail demo panel disabled. On next page reload it will disappear.';
  15. }
  16. $emails_module = NewsletterEmails::instance();
  17. $emails = $wpdb->get_results( "select * from " . NEWSLETTER_EMAILS_TABLE . " where type='message' order by id desc limit 5" );
  18. $users_module = NewsletterUsers::instance();
  19. $query = "select * from " . NEWSLETTER_USERS_TABLE . " order by id desc";
  20. $query .= " limit 10";
  21. $subscribers = $wpdb->get_results( $query );
  22. // Retrieves the last standard newsletter
  23. $last_email = $wpdb->get_row(
  24. $wpdb->prepare( "select * from " . NEWSLETTER_EMAILS_TABLE . " where type='message' and status in ('sent', 'sending') and send_on<%d order by id desc limit 1", time() ) );
  25. if ( $last_email ) {
  26. $last_email_sent = $last_email->sent;
  27. $last_email_opened = NewsletterStatistics::instance()->get_open_count( $last_email->id );
  28. $last_email_notopened = $last_email_sent - $last_email_opened;
  29. $last_email_clicked = NewsletterStatistics::instance()->get_click_count( $last_email->id );
  30. $last_email_opened -= $last_email_clicked;
  31. $overall_sent = $wpdb->get_var( "select sum(sent) from " . NEWSLETTER_EMAILS_TABLE . " where type='message' and status in ('sent', 'sending')" );
  32. $overall_opened = $wpdb->get_var( "select count(distinct user_id,email_id) from " . NEWSLETTER_STATS_TABLE );
  33. $overall_notopened = $overall_sent - $overall_opened;
  34. $overall_clicked = $wpdb->get_var( "select count(distinct user_id,email_id) from " . NEWSLETTER_STATS_TABLE . " where url<>''" );
  35. $overall_opened -= $overall_clicked;
  36. } else {
  37. $last_email_opened = 500;
  38. $last_email_notopened = 400;
  39. $last_email_clicked = 200;
  40. $overall_opened = 500;
  41. $overall_notopened = 400;
  42. $overall_clicked = 200;
  43. }
  44. $months = $wpdb->get_results( "select count(*) as c, concat(year(created), '-', date_format(created, '%m')) as d "
  45. . "from " . NEWSLETTER_USERS_TABLE . " where status='C' "
  46. . "group by concat(year(created), '-', date_format(created, '%m')) order by d desc limit 12" );
  47. $values = array();
  48. $labels = array();
  49. foreach ( $months as $month ) {
  50. $values[] = (int) $month->c;
  51. $labels[] = date( "M y", date_create_from_format( "Y-m", $month->d )->getTimestamp() );
  52. }
  53. $values = array_reverse( $values );
  54. $labels = array_reverse( $labels );
  55. ?>
  56. <div class="wrap" id="tnp-wrap">
  57. <?php include NEWSLETTER_DIR . '/tnp-header.php'; ?>
  58. <div id="tnp-heading">
  59. <h2><?php _e( 'Dashboard', 'newsletter' ) ?></h2>
  60. <p><?php _e( 'Your powerful control panel', 'newsletter' ) ?></p>
  61. </div>
  62. <div id="tnp-body" class="tnp-main-index">
  63. <div id="dashboard-widgets-wrap">
  64. <div id="dashboard-widgets" class="metabox-holder">
  65. <div id="postbox-container-1" class="postbox-container">
  66. <div id="normal-sortables" class="meta-box-sortables ui-sortable">
  67. <!-- START Statistics -->
  68. <div id="tnp-dash-statistics" class="postbox">
  69. <h3><?php _e( 'Statistics', 'newsletter' ) ?>
  70. <a href="<?php echo NewsletterStatistics::$instance->get_admin_page_url( 'index' ); ?>">
  71. <i class="fa fa-chart-bar"></i> <?php _e( 'Statistics', 'newsletter' ) ?>
  72. </a>
  73. </h3>
  74. <div class="inside">
  75. <?php if ( ! $last_email ) { ?>
  76. <p style="text-align: center">
  77. <?php _e( 'These charts are only for example:<br>create and send your first newsletter to have real statistics!', 'newsletter' ) ?>
  78. </p>
  79. <?php } ?>
  80. <div class="row tnp-row-pie-charts">
  81. <div class="col-md-6">
  82. <canvas id="tnp-rates1-chart"></canvas>
  83. <p style="text-align: center"><?php _e( 'Last Newsletter', 'newsletter' ) ?></p>
  84. </div>
  85. <div class="col-md-6">
  86. <canvas id="tnp-rates2-chart"></canvas>
  87. <p style="text-align: center"><?php _e( 'Overall', 'newsletter' ) ?></p>
  88. </div>
  89. </div>
  90. <script type="text/javascript">
  91. var rates1 = {
  92. labels: [
  93. "Not opened",
  94. "Opened",
  95. "Clicked"
  96. ],
  97. datasets: [
  98. {
  99. data: [<?php echo $last_email_notopened; ?>, <?php echo $last_email_opened; ?>, <?php echo $last_email_clicked ?>],
  100. backgroundColor: [
  101. "#ECF0F1",
  102. "#E67E22",
  103. "#27AE60"
  104. ],
  105. hoverBackgroundColor: [
  106. "#ECF0F1",
  107. "#E67E22",
  108. "#27AE60"
  109. ]
  110. }]
  111. };
  112. var rates2 = {
  113. labels: [
  114. "Not opened",
  115. "Opened",
  116. "Clicked"
  117. ],
  118. datasets: [
  119. {
  120. data: [<?php echo $overall_notopened; ?>, <?php echo $overall_opened; ?>, <?php echo $overall_clicked ?>],
  121. backgroundColor: [
  122. "#ECF0F1",
  123. "#E67E22",
  124. "#27AE60"
  125. ],
  126. hoverBackgroundColor: [
  127. "#ECF0F1",
  128. "#E67E22",
  129. "#27AE60"
  130. ]
  131. }]
  132. };
  133. jQuery(document).ready(function ($) {
  134. ctx1 = $('#tnp-rates1-chart').get(0).getContext("2d");
  135. ctx2 = $('#tnp-rates2-chart').get(0).getContext("2d");
  136. myPieChart1 = new Chart(ctx1, {
  137. type: 'doughnut',
  138. data: rates1,
  139. options: {legend: {display: false, labels: {boxWidth: 10}}}
  140. });
  141. myPieChart2 = new Chart(ctx2, {
  142. type: 'doughnut',
  143. data: rates2,
  144. options: {legend: {display: false, labels: {boxWidth: 10}}}
  145. });
  146. });
  147. </script>
  148. </div>
  149. </div>
  150. <!-- END Statistics -->
  151. <!-- START Statistics -->
  152. <div id="tnp-dash-statistics" class="postbox">
  153. <h3><?php _e( 'Subscriptions', 'newsletter' ) ?></h3>
  154. <div class="inside">
  155. <div id="canvas-holder">
  156. <canvas id="tnp-events-chart-canvas"></canvas>
  157. </div>
  158. <script type="text/javascript">
  159. var events_data = {
  160. labels: <?php echo json_encode( $labels ) ?>,
  161. datasets: [
  162. {
  163. label: "<?php _e( 'Subscriptions', 'newsletter' ) ?>",
  164. fill: true,
  165. strokeColor: "#27AE60",
  166. backgroundColor: "#ECF0F1",
  167. borderColor: "#27AE60",
  168. pointBorderColor: "#27AE60",
  169. pointBackgroundColor: "#ECF0F1",
  170. data: <?php echo json_encode( $values ) ?>
  171. }
  172. ]
  173. };
  174. jQuery(document).ready(function ($) {
  175. ctxe = $('#tnp-events-chart-canvas').get(0).getContext("2d");
  176. eventsLineChart = new Chart(ctxe, {
  177. type: 'line', data: events_data,
  178. options: {
  179. scales: {
  180. xAxes: [{
  181. type: "category",
  182. "id": "x-axis-1",
  183. gridLines: {display: false},
  184. ticks: {fontFamily: "Source Sans Pro"}
  185. }],
  186. yAxes: [
  187. {
  188. type: "linear",
  189. "id": "y-axis-1",
  190. gridLines: {display: false},
  191. ticks: {fontFamily: "Source Sans Pro"}
  192. },
  193. ]
  194. },
  195. }
  196. });
  197. });
  198. </script>
  199. </div>
  200. </div>
  201. <!-- END Statistics -->
  202. <!-- START Documentation -->
  203. <div id="tnp-dash-documentation" class="postbox">
  204. <h3><?php _e( 'Documentation', 'newsletter' ) ?>
  205. <a href="https://www.thenewsletterplugin.com/plugins/newsletter/newsletter-documentation"
  206. target="_blank">
  207. <i class="fa fa-life-ring"></i> <?php _e( 'Read all', 'newsletter' ) ?>
  208. </a>
  209. </h3>
  210. <div class="inside">
  211. <!-- <div class="tnp-video-container">
  212. <iframe width="480" height="360"
  213. src="https://www.youtube.com/embed/JaxK7XwqvVI?rel=0" frameborder="0"
  214. allowfullscreen></iframe>
  215. </div> -->
  216. <div>
  217. <a class="orange"
  218. href="https://www.thenewsletterplugin.com/plugins/newsletter/newsletter-documentation/email-sending-issues"
  219. target="_blank">
  220. <i class="fa fa-exclamation-triangle"></i> <?php _e( 'Problem sending messages? Start here!', 'newsletter' ) ?>
  221. </a>
  222. </div>
  223. <div>
  224. <a class="blue" href="https://www.thenewsletterplugin.com/support/video-tutorials"
  225. target="_blank">
  226. <i class="fa fa-youtube-play"></i> <?php _e( 'All Video Tutorials', 'newsletter' ) ?>
  227. </a>
  228. </div>
  229. <div>
  230. <a class="purple"
  231. href="https://www.thenewsletterplugin.com/plugins/newsletter/newsletter-preferences"
  232. target="_blank">
  233. <i class="fa fa-question-circle"></i> <?php _e( 'Learn how to segment your suscribers', 'newsletter' ) ?>
  234. </a>
  235. </div>
  236. </div>
  237. </div>
  238. <!-- END Documentation -->
  239. </div>
  240. </div>
  241. <div id="postbox-container-2" class="postbox-container">
  242. <div id="side-sortables" class="meta-box-sortables ui-sortable">
  243. <!-- START Newsletters -->
  244. <div id="tnp-dash-newsletters" class="postbox">
  245. <h3><?php _e( 'Newsletters', 'newsletter' ) ?>
  246. <a href="<?php echo $emails_module->get_admin_page_url( 'index' ); ?>">
  247. <i class="fa fa-list"></i> <?php _e( 'List', 'newsletter' ) ?>
  248. </a>
  249. <a href="<?php echo $emails_module->get_admin_page_url( 'theme' ); ?>">
  250. <i class="fa fa-plus-square"></i> <?php _e( 'New', 'newsletter' ) ?>
  251. </a>
  252. </h3>
  253. <div class="inside">
  254. <table width="100%">
  255. <?php
  256. foreach ( $emails as &$email ) { ?>
  257. <tr>
  258. <td><?php
  259. if ( $email->subject ) {
  260. echo htmlspecialchars( $email->subject );
  261. } else {
  262. echo "Newsletter #" . $email->id;
  263. }
  264. ?>
  265. </td>
  266. <td>
  267. <?php $emails_module->show_email_status_label( $email ) ?>
  268. </td>
  269. <td>
  270. <?php $emails_module->show_email_progress_bar( $email, array( 'scheduled' => true ) ) ?>
  271. </td>
  272. <td style="white-space:nowrap">
  273. <?php echo $emails_module->get_edit_button($email) ?>
  274. </td>
  275. </tr>
  276. <?php } ?>
  277. </table>
  278. </div>
  279. </div>
  280. <!-- END Newsletters -->
  281. <?php if ( empty( Newsletter::instance()->options['contract_key'] ) ) { ?>
  282. <!-- START Premium -->
  283. <div id="tnp-dash-premium" class="postbox">
  284. <h3><?php _e( 'Premium', 'newsletter' ) ?>
  285. <a href="https://www.thenewsletterplugin.com/extensions" target="_blank">
  286. <i class="fa fa-trophy"></i> <?php _e( 'Buy', 'newsletter' ) ?>
  287. </a>
  288. </h3>
  289. <div class="inside">
  290. <div>
  291. <a href="https://www.thenewsletterplugin.com/extensions" target="_blank">
  292. <img style="width: 100%;"
  293. src="https://cdn.thenewsletterplugin.com/dashboard01.gif">
  294. </a>
  295. </div>
  296. <div>
  297. <a href="https://www.thenewsletterplugin.com/extensions" target="_blank">
  298. <img style="width: 100%;"
  299. src="https://cdn.thenewsletterplugin.com/dashboard02.png">
  300. </a>
  301. </div>
  302. </div>
  303. </div>
  304. <!-- END Premium -->
  305. <?php } ?>
  306. </div>
  307. </div>
  308. <div id="postbox-container-3" class="postbox-container">
  309. <div id="column3-sortables" class="meta-box-sortables ui-sortable">
  310. <!-- START Subscribers -->
  311. <div id="tnp-dash-subscribers" class="postbox">
  312. <h3><?php _e( 'Last Subscribers', 'newsletter' ) ?>
  313. <a href="<?php echo $users_module->get_admin_page_url( 'index' ); ?>">
  314. <i class="fa fa-users"></i> <?php _e( 'List', 'newsletter' ) ?>
  315. </a>
  316. <a href="<?php echo $users_module->get_admin_page_url( 'new' ); ?>">
  317. <i class="fa fa-user-plus"></i> <?php _e( 'New', 'newsletter' ) ?>
  318. </a>
  319. </h3>
  320. <div class="inside">
  321. <table width="100%">
  322. <?php foreach ( $subscribers as $s ) { ?>
  323. <tr>
  324. <td><?php echo esc_html( $s->email ) ?><br>
  325. <?php echo esc_html( $s->name ) ?> <?php echo esc_html( $s->surname ) ?>
  326. </td>
  327. <td><?php echo $emails_module->get_user_status_label( $s ) ?></td>
  328. <td style="white-space:nowrap">
  329. <a class="button-primary tnp-button-white"
  330. title="<?php _e( 'Edit', 'newsletter' ) ?>"
  331. href="<?php echo $users_module->get_admin_page_url( 'edit' ); ?>&amp;id=<?php echo $s->id; ?>"><i
  332. class="fa fa-edit"></i></a>
  333. <a title="<?php _e( 'Profile', 'newsletter' ) ?>"
  334. href="<?php echo home_url( '/' ) ?>?na=p&nk=<?php echo $s->id . '-' . $s->token; ?>"
  335. class="button-primary tnp-button-white" target="_blank"><i
  336. class="fa fa-user"></i></a>
  337. </td>
  338. </tr>
  339. <?php } ?>
  340. </table>
  341. </div>
  342. </div>
  343. <!-- END Subscribers -->
  344. </div>
  345. </div>
  346. </div>
  347. </div>
  348. </div>
  349. <?php include NEWSLETTER_DIR . '/tnp-footer.php'; ?>
  350. </div>