PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.1.14
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.1.14
2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.2 All 57 releases
easy-invoice / includes / Admin / EasyInvoiceAdmin.php

EasyInvoiceAdmin.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.1.14, at includes/Admin/EasyInvoiceAdmin.php

583 lines 19.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * EasyInvoice Admin Class
4 *
5 * @package Easy_Invoice
6 * @subpackage Admin
7 */
8
9 namespace EasyInvoice\Admin;
10
11 use EasyInvoice\Admin\AdminAssets;
12 use EasyInvoice\Constants\PagesSlugs;
13 use EasyInvoice\Controllers\InvoiceController;
14 use EasyInvoice\Controllers\QuoteController;
15 use EasyInvoice\Controllers\ClientController;
16 use EasyInvoice\Controllers\SettingsController;
17 use EasyInvoice\Controllers\ReportController;
18 use EasyInvoice\Controllers\DashboardController;
19 use EasyInvoice\Controllers\PaymentController;
20
21 /**
22 * EasyInvoiceAdmin is the main admin class that initializes all controllers
23 */
24 class EasyInvoiceAdmin {
25 /**
26 * Invoice controller instance
27 *
28 * @var InvoiceController
29 */
30 private $invoice_controller;
31
32 /**
33 * Quote controller instance
34 *
35 * @var QuoteController
36 */
37 private $quote_controller;
38
39 /**
40 * Client controller instance
41 *
42 * @var ClientController
43 */
44 private $client_controller;
45
46 /**
47 * Settings controller instance
48 *
49 * @var SettingsController
50 */
51 private $settings_controller;
52
53 /**
54 * Report controller instance
55 *
56 * @var ReportController
57 */
58 private $report_controller;
59
60 /**
61 * Dashboard controller instance
62 *
63 * @var DashboardController
64 */
65 private $dashboard_controller;
66
67 /**
68 * Payment controller instance
69 *
70 * @var PaymentController
71 */
72 private $payment_controller;
73
74 /**
75 * Template Builder controller instance
76 *
77 * @var \EasyInvoicePro\Controllers\TemplateBuilderController
78 */
79 private $template_builder_controller;
80
81 /**
82 * Constructor
83 */
84 public function __construct() {
85 $this->invoice_controller = new InvoiceController();
86 $this->quote_controller = new QuoteController();
87 $this->client_controller = new ClientController();
88 $this->settings_controller = new SettingsController();
89 $this->report_controller = new ReportController();
90 $this->dashboard_controller = new DashboardController();
91 $this->payment_controller = new PaymentController();
92
93 // Initialize Template Builder controller if Pro is active
94 if (easy_invoice_has_pro() && class_exists('\EasyInvoicePro\Controllers\TemplateBuilderController')) {
95 $this->template_builder_controller = new \EasyInvoicePro\Controllers\TemplateBuilderController();
96 }
97 }
98
99 /**
100 * Initialize the admin class
101 */
102 public function init() {
103 // Add menu items
104 add_action('admin_menu', array($this, 'registerMenuPages'));
105
106 // Register admin assets
107 $admin_assets = new AdminAssets();
108 $admin_assets->register();
109
110 // Register invoice preview page
111 add_action('admin_init', array($this, 'registerPreviewPage'));
112
113 // Ensure proper page titles to avoid WordPress core issues
114 add_filter('admin_title', array($this, 'setAdminTitle'));
115
116 // Hide admin UI
117 add_action('admin_head', array($this, 'hideAdminUi'));
118
119 // Initialize controllers
120 $this->invoice_controller->init();
121 $this->quote_controller->init();
122 $this->client_controller->init();
123 $this->settings_controller->init();
124 $this->report_controller->init();
125 $this->dashboard_controller->init();
126 $this->payment_controller->init();
127
128 // Main content hook
129 add_action('easy_invoice_admin_main_content', array($this, 'mainPageContent'));
130 }
131
132 /**
133 * Register admin menu pages
134 */
135 public function registerMenuPages() {
136 // Main menu item
137 add_menu_page(
138 __('Easy Invoice', 'easy-invoice'),
139 __('Easy Invoice', 'easy-invoice'),
140 'manage_options',
141 PagesSlugs::DASHBOARD,
142 array($this, 'displayMainPage'),
143 'dashicons-media-text',
144 25
145 );
146
147 // Dashboard submenu
148 add_submenu_page(
149 'easy-invoice',
150 __('Dashboard', 'easy-invoice'),
151 __('Dashboard', 'easy-invoice'),
152 'manage_options',
153 PagesSlugs::DASHBOARD,
154 array($this, 'displayMainPage')
155 );
156
157 // All invoices submenu
158 add_submenu_page(
159 'easy-invoice',
160 __('All Invoices', 'easy-invoice'),
161 __('All Invoices', 'easy-invoice'),
162 'manage_options',
163 PagesSlugs::ALL_INVOICES,
164 array($this, 'displayMainPage')
165 );
166
167 // Add new invoice submenu
168 add_submenu_page(
169 'easy-invoice-hidden',
170 __('Add New Invoice', 'easy-invoice'),
171 __('Add New', 'easy-invoice'),
172 'manage_options',
173 PagesSlugs::INVOICE_NEW,
174 array($this, 'displayMainPage')
175 );
176
177 // All quotes submenu
178 add_submenu_page(
179 'easy-invoice',
180 __('All Quotes', 'easy-invoice'),
181 __('All Quotes', 'easy-invoice'),
182 'manage_options',
183 PagesSlugs::ALL_QUOTES,
184 array($this, 'displayMainPage')
185 );
186
187 // Add new quote submenu
188 add_submenu_page(
189 'easy-invoice-hidden',
190 __('Add New Quote', 'easy-invoice'),
191 __('Add New Quote', 'easy-invoice'),
192 'manage_options',
193 PagesSlugs::QUOTE_NEW,
194 array($this, 'displayMainPage')
195 );
196
197 // Payments submenu
198 add_submenu_page(
199 'easy-invoice-hidden',
200 __('Payments', 'easy-invoice'),
201 __('Payments', 'easy-invoice'),
202 'manage_options',
203 PagesSlugs::PAYMENTS,
204 array($this, 'displayMainPage')
205 );
206
207 // Add new payment submenu
208 add_submenu_page(
209 'easy-invoice-hidden',
210 __('Add New Payment', 'easy-invoice'),
211 __('Add New Payment', 'easy-invoice'),
212 'manage_options',
213 PagesSlugs::PAYMENT_NEW,
214 array($this, 'displayMainPage')
215 );
216
217 // Clients submenu
218 add_submenu_page(
219 'easy-invoice',
220 __('All Clients', 'easy-invoice'),
221 __('All Clients', 'easy-invoice'),
222 'edit_posts',
223 PagesSlugs::CLIENTS,
224 array($this, 'displayMainPage')
225 );
226
227 // Item Library submenu - only show if Pro is active
228 if (easy_invoice_has_pro()) {
229 add_submenu_page(
230 'easy-invoice',
231 __('Item Library', 'easy-invoice'),
232 __('Item Library', 'easy-invoice'),
233 'manage_options',
234 'easy-invoice-pro-item-library',
235 array($this, 'displayMainPage')
236 );
237
238 // Template Builder submenu - only show if Pro is active
239 add_submenu_page(
240 'easy-invoice',
241 __('Template Builder', 'easy-invoice'),
242 __('Template Builder', 'easy-invoice'),
243 'manage_options',
244 'easy-invoice-templates',
245 array($this, 'displayMainPage')
246 );
247
248 // Create New Template submenu - only show if Pro is active
249 add_submenu_page(
250 'easy-invoice-hidden',
251 __('Create New Template', 'easy-invoice'),
252 __('Create New', 'easy-invoice'),
253 'manage_options',
254 'easy-invoice-templates-new',
255 array($this, 'displayMainPage')
256 );
257
258 // Template Builder Page submenu - only show if Pro is active (hidden page)
259 add_submenu_page(
260 'easy-invoice-hidden',
261 __('Template Builder Page', 'easy-invoice'),
262 __('Template Builder Page', 'easy-invoice'),
263 'manage_options',
264 'easy-invoice-template-builder',
265 array($this, 'displayMainPage')
266 );
267 }
268
269 // Hidden submenu pages - not shown in the menu but accessible
270 add_submenu_page(
271 'easy-invoice-hidden', // Use main menu as parent to avoid title issues
272 __('Edit Client', 'easy-invoice'),
273 __('Edit Client', 'easy-invoice'),
274 'manage_options',
275 PagesSlugs::CLIENT_EDIT,
276 array($this, 'displayMainPage')
277 );
278
279 add_submenu_page(
280 'easy-invoice-hidden', // Use main menu as parent to avoid title issues
281 __('View Client', 'easy-invoice'),
282 __('View Client', 'easy-invoice'),
283 'manage_options',
284 PagesSlugs::CLIENT_VIEW,
285 array($this, 'displayMainPage')
286 );
287
288 add_submenu_page(
289 'easy-invoice-hidden', // Use main menu as parent to avoid title issues
290 __('Preview Invoice', 'easy-invoice'),
291 __('Preview Invoice', 'easy-invoice'),
292 'manage_options',
293 PagesSlugs::INVOICE_PREVIEW,
294 array($this, 'displayPreviewPage')
295 );
296
297 add_submenu_page(
298 'easy-invoice-hidden', // Use main menu as parent to avoid title issues
299 __('Preview Quote', 'easy-invoice'),
300 __('Preview Quote', 'easy-invoice'),
301 'manage_options',
302 PagesSlugs::QUOTE_PREVIEW,
303 array($this, 'displayMainPage')
304 );
305
306 add_submenu_page(
307 'easy-invoice',
308 __('Reports', 'easy-invoice'),
309 __('Reports', 'easy-invoice'),
310 'manage_options',
311 PagesSlugs::REPORTS,
312 array($this, 'displayMainPage')
313 );
314
315 // Settings submenu
316 add_submenu_page(
317 'easy-invoice',
318 __('Settings', 'easy-invoice'),
319 __('Settings', 'easy-invoice'),
320 'manage_options',
321 PagesSlugs::SETTINGS,
322 array($this, 'displayMainPage')
323 );
324
325 // License submenu
326 add_submenu_page(
327 'easy-invoice',
328 __('License', 'easy-invoice'),
329 __('License', 'easy-invoice'),
330 'manage_options',
331 PagesSlugs::LICENSE,
332 array($this, 'displayMainPage')
333 );
334
335 // Free vs Pro submenu - only show in free version
336 if (!easy_invoice_has_pro()) {
337 add_submenu_page(
338 'easy-invoice',
339 __('Free vs Pro', 'easy-invoice'),
340 __('Free vs Pro', 'easy-invoice'),
341 'manage_options',
342 'easy-invoice-free-vs-pro',
343 array($this, 'displayMainPage')
344 );
345 }
346
347 // Join Community submenu
348 add_submenu_page(
349 'easy-invoice-hidden',
350 __('Join Community', 'easy-invoice'),
351 __('Join Community', 'easy-invoice'),
352 'read',
353 'easy-invoice-join-community',
354 array($this, 'redirectToCommunity')
355 );
356 }
357
358 /**
359 * Redirect to community page
360 */
361 public function redirectToCommunity() {
362 wp_redirect(esc_url_raw('https://www.facebook.com/groups/mantrabraincommunity'));
363 exit;
364 }
365
366 /**
367 * Register invoice preview page
368 */
369 public function registerPreviewPage() {
370 //add_action('admin_action_easy_invoice_preview', array($this, 'displayPreviewPage'));
371 }
372
373 /**
374 * Display main page
375 */
376 public function displayMainPage() {
377 include EASY_INVOICE_PLUGIN_DIR . 'templates/main-template.php';
378 }
379
380 /**
381 * Display preview page
382 */
383 public function displayPreviewPage() {
384 $this->invoice_controller->display(['page' => PagesSlugs::INVOICE_PREVIEW]);
385 }
386
387 /**
388 * Display license page
389 */
390 public function displayLicensePage() {
391 include EASY_INVOICE_PLUGIN_DIR . 'templates/admin/license-page.php';
392 }
393
394 /**
395 * Handle main page content based on the current page
396 *
397 * @param string $page Current page
398 */
399 public function mainPageContent($page) {
400 switch ($page) {
401 case PagesSlugs::DASHBOARD:
402 $this->dashboard_controller->display(['page' => PagesSlugs::DASHBOARD]);
403 break;
404
405 case PagesSlugs::ALL_INVOICES:
406 $this->invoice_controller->display(['page' => PagesSlugs::ALL_INVOICES]);
407 break;
408
409 case PagesSlugs::INVOICE_NEW:
410 $this->invoice_controller->display(['page' => PagesSlugs::INVOICE_NEW]);
411 break;
412
413 case PagesSlugs::INVOICE_PREVIEW:
414 $this->invoice_controller->display(['page' => PagesSlugs::INVOICE_PREVIEW]);
415 break;
416
417 case PagesSlugs::ALL_QUOTES:
418 $this->quote_controller->display(['page' => PagesSlugs::ALL_QUOTES]);
419 break;
420
421 case PagesSlugs::QUOTE_NEW:
422 $this->quote_controller->display(['page' => PagesSlugs::QUOTE_NEW]);
423 break;
424
425 case PagesSlugs::QUOTE_PREVIEW:
426 $this->quote_controller->display(['page' => PagesSlugs::QUOTE_PREVIEW]);
427 break;
428
429 case PagesSlugs::PAYMENTS:
430 if (isset($_GET['action'])) {
431 $this->payment_controller->display(['page' => $_GET['action']]);
432 } else {
433 $this->payment_controller->display(['page' => PagesSlugs::PAYMENTS]);
434 }
435 break;
436
437 case PagesSlugs::PAYMENT_NEW:
438 $this->payment_controller->display(['page' => PagesSlugs::PAYMENT_NEW]);
439 break;
440
441 case PagesSlugs::CLIENTS:
442 $this->client_controller->display(['page' => PagesSlugs::CLIENTS]);
443 break;
444
445 case PagesSlugs::CLIENT_EDIT:
446 $this->client_controller->display(['page' => PagesSlugs::CLIENT_EDIT]);
447 break;
448
449 // Handle Pro features
450 case 'easy-invoice-pro-item-library':
451 if (easy_invoice_has_pro()) {
452 // Use the Pro controller's displayMainPage method like other controllers
453 if (class_exists('\EasyInvoicePro\Controllers\ItemLibraryController')) {
454 $item_library_controller = new \EasyInvoicePro\Controllers\ItemLibraryController();
455 $item_library_controller->displayMainPage();
456 }
457 }
458 break;
459
460 case 'easy-invoice-templates':
461 if (easy_invoice_has_pro()) {
462 // Use the Pro controller's displayMainPage method like other controllers
463 if (class_exists('\EasyInvoicePro\Controllers\TemplateBuilderController')) {
464 $template_builder_controller = new \EasyInvoicePro\Controllers\TemplateBuilderController();
465 $template_builder_controller->displayMainPage();
466 }
467 }
468 break;
469
470 case 'easy-invoice-template-builder':
471 if (easy_invoice_has_pro()) {
472 // Use the Pro controller's displayMainPage method like other controllers
473 if (class_exists('\EasyInvoicePro\Controllers\TemplateBuilderController')) {
474 $template_builder_controller = new \EasyInvoicePro\Controllers\TemplateBuilderController();
475 $template_builder_controller->displayMainPage();
476 }
477 }
478 break;
479
480 case PagesSlugs::CLIENT_VIEW:
481 $this->client_controller->display(['page' => PagesSlugs::CLIENT_VIEW]);
482 break;
483
484 case PagesSlugs::REPORTS:
485 $this->report_controller->display(['page' => PagesSlugs::REPORTS]);
486 break;
487
488 case PagesSlugs::SETTINGS:
489 $this->settings_controller->display(['page' => PagesSlugs::SETTINGS]);
490 break;
491
492 case PagesSlugs::LICENSE:
493 $this->displayLicensePage();
494 break;
495
496 case PagesSlugs::EMAIL_SETTINGS:
497 case PagesSlugs::EMAIL_SETTINGS_GENERAL:
498 case PagesSlugs::EMAIL_SETTINGS_INVOICE:
499 case PagesSlugs::EMAIL_SETTINGS_QUOTE:
500 case PagesSlugs::EMAIL_SETTINGS_PAYMENT:
501 $this->settings_controller->display(['page' => PagesSlugs::SETTINGS, 'subsection' => $page]);
502 break;
503
504 case 'easy-invoice-migration':
505 include EASY_INVOICE_PLUGIN_DIR . 'includes/Migration/templates/migration-page.php';
506 break;
507
508 case 'easy-invoice-free-vs-pro':
509 include EASY_INVOICE_PLUGIN_DIR . 'templates/admin/free-vs-pro-page.php';
510 break;
511
512 default:
513 $this->dashboard_controller->display(['page' => PagesSlugs::DASHBOARD]);
514 break;
515 }
516 }
517
518 /**
519 * Set proper admin title to avoid WordPress core issues
520 *
521 * @param string $title The current admin title
522 * @return string The modified admin title
523 */
524 public function setAdminTitle($title) {
525 $current_page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
526
527 // Only modify titles for our plugin pages
528 if (strpos($current_page, 'easy-invoice') === 0 || strpos($current_page, 'easy-quote') === 0) {
529 $page_titles = [
530 'easy-invoice' => __('Dashboard', 'easy-invoice'),
531 'easy-invoice-all' => __('All Invoices', 'easy-invoice'),
532 'easy-invoice-builder' => __('Add New Invoice', 'easy-invoice'),
533 'easy-invoice-preview' => __('Preview Invoice', 'easy-invoice'),
534 'easy-quote-all' => __('All Quotes', 'easy-invoice'),
535 'easy-invoice-quote-builder' => __('Add New Quote', 'easy-invoice'),
536 'easy-quote-preview' => __('Preview Quote', 'easy-invoice'),
537 'easy-invoice-payments' => __('Payments', 'easy-invoice'),
538 'easy-invoice-payment-new' => __('Add New Payment', 'easy-invoice'),
539 'easy-invoice-clients' => __('Clients', 'easy-invoice'),
540 'easy-invoice-client-edit' => __('Edit Client', 'easy-invoice'),
541 'easy-invoice-client-view' => __('View Client', 'easy-invoice'),
542 'easy-invoice-reports' => __('Reports', 'easy-invoice'),
543 'easy-invoice-settings' => __('Settings', 'easy-invoice'),
544 'easy-invoice-email-settings' => __('Email Settings', 'easy-invoice'),
545 'easy-invoice-migration' => __('Migration', 'easy-invoice'),
546 'easy-invoice-free-vs-pro' => __('Free vs Pro', 'easy-invoice'),
547 ];
548
549 if (isset($page_titles[$current_page])) {
550 return $page_titles[$current_page] . ' - ' . get_bloginfo('name');
551 }
552 }
553
554 return $title;
555 }
556
557 /**
558 * Hide the WordPress admin UI for our custom pages
559 */
560 public function hideAdminUi() {
561 $screen = get_current_screen();
562 if ($screen && property_exists($screen, 'id') && strpos($screen->id, 'easy-invoice') !== false) {
563 ?>
564 <style>
565 #wpadminbar,
566 #adminmenumain,
567 #wpfooter {
568 display: none !important;
569 }
570 #wpcontent {
571 margin-left: 0 !important;
572 padding: 0 !important;
573 }
574 .wrap {
575 margin: 0 !important;
576 padding: 0 !important;
577 }
578 </style>
579 <?php
580 }
581 }
582 }
583