PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.1.2
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.1.2
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.2, at includes/Admin/EasyInvoiceAdmin.php

480 lines 15.2 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 * Constructor
76 */
77 public function __construct() {
78 $this->invoice_controller = new InvoiceController();
79 $this->quote_controller = new QuoteController();
80 $this->client_controller = new ClientController();
81 $this->settings_controller = new SettingsController();
82 $this->report_controller = new ReportController();
83 $this->dashboard_controller = new DashboardController();
84 $this->payment_controller = new PaymentController();
85 }
86
87 /**
88 * Initialize the admin class
89 */
90 public function init() {
91 // Add menu items
92 add_action('admin_menu', array($this, 'registerMenuPages'));
93
94 // Register admin assets
95 $admin_assets = new AdminAssets();
96 $admin_assets->register();
97
98 // Register invoice preview page
99 add_action('admin_init', array($this, 'registerPreviewPage'));
100
101 // Ensure proper page titles to avoid WordPress core issues
102 add_filter('admin_title', array($this, 'setAdminTitle'));
103
104 // Hide admin UI
105 add_action('admin_head', array($this, 'hideAdminUi'));
106
107 // Initialize controllers
108 $this->invoice_controller->init();
109 $this->quote_controller->init();
110 $this->client_controller->init();
111 $this->settings_controller->init();
112 $this->report_controller->init();
113 $this->dashboard_controller->init();
114 $this->payment_controller->init();
115
116 // Main content hook
117 add_action('easy_invoice_admin_main_content', array($this, 'mainPageContent'));
118 }
119
120 /**
121 * Register admin menu pages
122 */
123 public function registerMenuPages() {
124 // Main menu item
125 add_menu_page(
126 __('Easy Invoice', 'easy-invoice'),
127 __('Easy Invoice', 'easy-invoice'),
128 'manage_options',
129 PagesSlugs::DASHBOARD,
130 array($this, 'displayMainPage'),
131 'dashicons-media-text',
132 25
133 );
134
135 // Dashboard submenu
136 add_submenu_page(
137 'easy-invoice',
138 __('Dashboard', 'easy-invoice'),
139 __('Dashboard', 'easy-invoice'),
140 'manage_options',
141 PagesSlugs::DASHBOARD,
142 array($this, 'displayMainPage')
143 );
144
145 // All invoices submenu
146 add_submenu_page(
147 'easy-invoice',
148 __('All Invoices', 'easy-invoice'),
149 __('All Invoices', 'easy-invoice'),
150 'manage_options',
151 PagesSlugs::ALL_INVOICES,
152 array($this, 'displayMainPage')
153 );
154
155 // Add new invoice submenu
156 add_submenu_page(
157 'easy-invoice-hidden',
158 __('Add New Invoice', 'easy-invoice'),
159 __('Add New', 'easy-invoice'),
160 'manage_options',
161 PagesSlugs::INVOICE_NEW,
162 array($this, 'displayMainPage')
163 );
164
165 // All quotes submenu
166 add_submenu_page(
167 'easy-invoice',
168 __('All Quotes', 'easy-invoice'),
169 __('All Quotes', 'easy-invoice'),
170 'manage_options',
171 PagesSlugs::ALL_QUOTES,
172 array($this, 'displayMainPage')
173 );
174
175 // Add new quote submenu
176 add_submenu_page(
177 'easy-invoice-hidden',
178 __('Add New Quote', 'easy-invoice'),
179 __('Add New Quote', 'easy-invoice'),
180 'manage_options',
181 PagesSlugs::QUOTE_NEW,
182 array($this, 'displayMainPage')
183 );
184
185 // Payments submenu
186 add_submenu_page(
187 'easy-invoice-hidden',
188 __('Payments', 'easy-invoice'),
189 __('Payments', 'easy-invoice'),
190 'manage_options',
191 PagesSlugs::PAYMENTS,
192 array($this, 'displayMainPage')
193 );
194
195 // Add new payment submenu
196 add_submenu_page(
197 'easy-invoice-hidden',
198 __('Add New Payment', 'easy-invoice'),
199 __('Add New Payment', 'easy-invoice'),
200 'manage_options',
201 PagesSlugs::PAYMENT_NEW,
202 array($this, 'displayMainPage')
203 );
204
205 // Clients submenu
206 add_submenu_page(
207 'easy-invoice',
208 __('All Clients', 'easy-invoice'),
209 __('All Clients', 'easy-invoice'),
210 'manage_options',
211 PagesSlugs::CLIENTS,
212 array($this, 'displayMainPage')
213 );
214
215 // Hidden submenu pages - not shown in the menu but accessible
216 add_submenu_page(
217 'easy-invoice-hidden', // Use main menu as parent to avoid title issues
218 __('Edit Client', 'easy-invoice'),
219 __('Edit Client', 'easy-invoice'),
220 'manage_options',
221 PagesSlugs::CLIENT_EDIT,
222 array($this, 'displayMainPage')
223 );
224
225 add_submenu_page(
226 'easy-invoice-hidden', // Use main menu as parent to avoid title issues
227 __('View Client', 'easy-invoice'),
228 __('View Client', 'easy-invoice'),
229 'manage_options',
230 PagesSlugs::CLIENT_VIEW,
231 array($this, 'displayMainPage')
232 );
233
234 add_submenu_page(
235 'easy-invoice-hidden', // Use main menu as parent to avoid title issues
236 __('Preview Invoice', 'easy-invoice'),
237 __('Preview Invoice', 'easy-invoice'),
238 'manage_options',
239 PagesSlugs::INVOICE_PREVIEW,
240 array($this, 'displayPreviewPage')
241 );
242
243 add_submenu_page(
244 'easy-invoice-hidden', // Use main menu as parent to avoid title issues
245 __('Preview Quote', 'easy-invoice'),
246 __('Preview Quote', 'easy-invoice'),
247 'manage_options',
248 PagesSlugs::QUOTE_PREVIEW,
249 array($this, 'displayMainPage')
250 );
251
252 add_submenu_page(
253 'easy-invoice',
254 __('Reports', 'easy-invoice'),
255 __('Reports', 'easy-invoice'),
256 'manage_options',
257 PagesSlugs::REPORTS,
258 array($this, 'displayMainPage')
259 );
260
261 // Settings submenu
262 add_submenu_page(
263 'easy-invoice',
264 __('Settings', 'easy-invoice'),
265 __('Settings', 'easy-invoice'),
266 'manage_options',
267 PagesSlugs::SETTINGS,
268 array($this, 'displayMainPage')
269 );
270
271 // License submenu
272 add_submenu_page(
273 'easy-invoice',
274 __('License', 'easy-invoice'),
275 __('License', 'easy-invoice'),
276 'manage_options',
277 PagesSlugs::LICENSE,
278 array($this, 'displayMainPage')
279 );
280
281 // Free vs Pro submenu - only show in free version
282 if (!easy_invoice_has_pro()) {
283 add_submenu_page(
284 'easy-invoice',
285 __('Free vs Pro', 'easy-invoice'),
286 __('Free vs Pro', 'easy-invoice'),
287 'manage_options',
288 'easy-invoice-free-vs-pro',
289 array($this, 'displayMainPage')
290 );
291 }
292 }
293
294 /**
295 * Register invoice preview page
296 */
297 public function registerPreviewPage() {
298 //add_action('admin_action_easy_invoice_preview', array($this, 'displayPreviewPage'));
299 }
300
301 /**
302 * Display main page
303 */
304 public function displayMainPage() {
305 include EASY_INVOICE_PLUGIN_DIR . 'templates/main-template.php';
306 }
307
308 /**
309 * Display preview page
310 */
311 public function displayPreviewPage() {
312 $this->invoice_controller->display(['page' => PagesSlugs::INVOICE_PREVIEW]);
313 }
314
315 /**
316 * Display license page
317 */
318 public function displayLicensePage() {
319 include EASY_INVOICE_PLUGIN_DIR . 'templates/admin/license-page.php';
320 }
321
322 /**
323 * Handle main page content based on the current page
324 *
325 * @param string $page Current page
326 */
327 public function mainPageContent($page) {
328 switch ($page) {
329 case PagesSlugs::DASHBOARD:
330 $this->dashboard_controller->display(['page' => PagesSlugs::DASHBOARD]);
331 break;
332
333 case PagesSlugs::ALL_INVOICES:
334 $this->invoice_controller->display(['page' => PagesSlugs::ALL_INVOICES]);
335 break;
336
337 case PagesSlugs::INVOICE_NEW:
338 $this->invoice_controller->display(['page' => PagesSlugs::INVOICE_NEW]);
339 break;
340
341 case PagesSlugs::INVOICE_PREVIEW:
342 $this->invoice_controller->display(['page' => PagesSlugs::INVOICE_PREVIEW]);
343 break;
344
345 case PagesSlugs::ALL_QUOTES:
346 $this->quote_controller->display(['page' => PagesSlugs::ALL_QUOTES]);
347 break;
348
349 case PagesSlugs::QUOTE_NEW:
350 $this->quote_controller->display(['page' => PagesSlugs::QUOTE_NEW]);
351 break;
352
353 case PagesSlugs::QUOTE_PREVIEW:
354 $this->quote_controller->display(['page' => PagesSlugs::QUOTE_PREVIEW]);
355 break;
356
357 case PagesSlugs::PAYMENTS:
358 if (isset($_GET['action'])) {
359 $this->payment_controller->display(['page' => $_GET['action']]);
360 } else {
361 $this->payment_controller->display(['page' => PagesSlugs::PAYMENTS]);
362 }
363 break;
364
365 case PagesSlugs::PAYMENT_NEW:
366 $this->payment_controller->display(['page' => PagesSlugs::PAYMENT_NEW]);
367 break;
368
369 case PagesSlugs::CLIENTS:
370 $this->client_controller->display(['page' => PagesSlugs::CLIENTS]);
371 break;
372
373 case PagesSlugs::CLIENT_EDIT:
374 $this->client_controller->display(['page' => PagesSlugs::CLIENT_EDIT]);
375 break;
376
377 case PagesSlugs::CLIENT_VIEW:
378 $this->client_controller->display(['page' => PagesSlugs::CLIENT_VIEW]);
379 break;
380
381 case PagesSlugs::REPORTS:
382 $this->report_controller->display(['page' => PagesSlugs::REPORTS]);
383 break;
384
385 case PagesSlugs::SETTINGS:
386 $this->settings_controller->display(['page' => PagesSlugs::SETTINGS]);
387 break;
388
389 case PagesSlugs::LICENSE:
390 $this->displayLicensePage();
391 break;
392
393 case PagesSlugs::EMAIL_SETTINGS:
394 case PagesSlugs::EMAIL_SETTINGS_GENERAL:
395 case PagesSlugs::EMAIL_SETTINGS_INVOICE:
396 case PagesSlugs::EMAIL_SETTINGS_QUOTE:
397 case PagesSlugs::EMAIL_SETTINGS_PAYMENT:
398 $this->settings_controller->display(['page' => PagesSlugs::SETTINGS, 'subsection' => $page]);
399 break;
400
401 case 'easy-invoice-migration':
402 include EASY_INVOICE_PLUGIN_DIR . 'includes/Migration/templates/migration-page.php';
403 break;
404
405 case 'easy-invoice-free-vs-pro':
406 include EASY_INVOICE_PLUGIN_DIR . 'templates/admin/free-vs-pro-page.php';
407 break;
408
409 default:
410 $this->dashboard_controller->display(['page' => PagesSlugs::DASHBOARD]);
411 break;
412 }
413 }
414
415 /**
416 * Set proper admin title to avoid WordPress core issues
417 *
418 * @param string $title The current admin title
419 * @return string The modified admin title
420 */
421 public function setAdminTitle($title) {
422 $current_page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
423
424 // Only modify titles for our plugin pages
425 if (strpos($current_page, 'easy-invoice') === 0 || strpos($current_page, 'easy-quote') === 0) {
426 $page_titles = [
427 'easy-invoice' => __('Dashboard', 'easy-invoice'),
428 'easy-invoice-all' => __('All Invoices', 'easy-invoice'),
429 'easy-invoice-builder' => __('Add New Invoice', 'easy-invoice'),
430 'easy-invoice-preview' => __('Preview Invoice', 'easy-invoice'),
431 'easy-quote-all' => __('All Quotes', 'easy-invoice'),
432 'easy-invoice-quote-builder' => __('Add New Quote', 'easy-invoice'),
433 'easy-quote-preview' => __('Preview Quote', 'easy-invoice'),
434 'easy-invoice-payments' => __('Payments', 'easy-invoice'),
435 'easy-invoice-payment-new' => __('Add New Payment', 'easy-invoice'),
436 'easy-invoice-clients' => __('Clients', 'easy-invoice'),
437 'easy-invoice-client-edit' => __('Edit Client', 'easy-invoice'),
438 'easy-invoice-client-view' => __('View Client', 'easy-invoice'),
439 'easy-invoice-reports' => __('Reports', 'easy-invoice'),
440 'easy-invoice-settings' => __('Settings', 'easy-invoice'),
441 'easy-invoice-email-settings' => __('Email Settings', 'easy-invoice'),
442 'easy-invoice-migration' => __('Migration', 'easy-invoice'),
443 'easy-invoice-free-vs-pro' => __('Free vs Pro', 'easy-invoice'),
444 ];
445
446 if (isset($page_titles[$current_page])) {
447 return $page_titles[$current_page] . ' - ' . get_bloginfo('name');
448 }
449 }
450
451 return $title;
452 }
453
454 /**
455 * Hide the WordPress admin UI for our custom pages
456 */
457 public function hideAdminUi() {
458 $screen = get_current_screen();
459 if ($screen && property_exists($screen, 'id') && strpos($screen->id, 'easy-invoice') !== false) {
460 ?>
461 <style>
462 #wpadminbar,
463 #adminmenumain,
464 #wpfooter {
465 display: none !important;
466 }
467 #wpcontent {
468 margin-left: 0 !important;
469 padding: 0 !important;
470 }
471 .wrap {
472 margin: 0 !important;
473 padding: 0 !important;
474 }
475 </style>
476 <?php
477 }
478 }
479 }
480