Completed
Pull Request — 3.1.x (#125)
by Matt
02:17
created

acp/autogroups_module.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
*
4
* Auto Groups extension for the phpBB Forum Software package.
5
*
6
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
7
* @license GNU General Public License, version 2 (GPL-2.0)
8
*
9
*/
10
11
namespace phpbb\autogroups\acp;
12
13
class autogroups_module
14
{
15
	public $page_title;
16
	public $tpl_name;
17
	public $u_action;
18
19
	public function main($id, $mode)
20
	{
21
		global $phpbb_container;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
22
23
		/** @var \phpbb\request\request $request */
24
		$request = $phpbb_container->get('request');
25
26
		/** @var \phpbb\user $language */
27
		$user = $phpbb_container->get('user');
28
29
		// Add the auto groups ACP lang file
30
		$user->add_lang_ext('phpbb/autogroups', 'autogroups_acp');
31
32
		// Get an instance of the admin controller
33
		$admin_controller = $phpbb_container->get('phpbb.autogroups.admin_controller');
34
35
		// Requests
36
		$action = $request->variable('action', '');
37
		$autogroups_id = $request->variable('autogroups_id', 0);
38
39
		// Make the $u_action url available in the admin controller
40
		$admin_controller->set_page_url($this->u_action);
41
42
		// Load a template from adm/style for our ACP auto groups
43
		$this->tpl_name = 'manage_autogroups';
44
45
		// Set the page title for our ACP auto groups
46
		$this->page_title = $user->lang('ACP_AUTOGROUPS_MANAGE');
47
48
		// Quick-submit settings from the general options form
49
		if ($request->is_set_post('generalsubmit'))
50
		{
51
			$admin_controller->submit_autogroups_options();
52
		}
53
54
		// Perform any actions submitted by the user
55
		switch ($action)
56
		{
57
			case 'add':
58
			case 'edit':
59
				// Set the page title for our ACP auto groups
60
				$this->page_title = $user->lang(strtoupper("ACP_AUTOGROUPS_$action"));
61
62
				// Load the save auto group handle in the admin controller
63
				$admin_controller->save_autogroup_rule($autogroups_id);
64
65
				// Return to stop execution of this script
66
				return;
67
			break;
68
69
			case 'sync':
70
				// Resync applies an auto group check against all users
71
				$admin_controller->resync_autogroup_rule($autogroups_id);
72
			break;
73
74
			case 'delete':
75
				// Use a confirm box routine when deleting an auto group rule
76
				if (confirm_box(true))
77
				{
78
					// Delete auto group rule on confirmation from the user
79
					$admin_controller->delete_autogroup_rule($autogroups_id);
80
				}
81
				else
82
				{
83
					// Request confirmation from the user to delete the auto group rule
84
					confirm_box(false, $user->lang('ACP_AUTOGROUPS_DELETE_CONFIRM'), build_hidden_fields(array(
85
						'autogroups_id'	=> $autogroups_id,
86
						'mode'			=> $mode,
87
						'action'		=> $action,
88
					)));
89
				}
90
			break;
91
		}
92
93
		// Display auto group rules
94
		$admin_controller->display_autogroups();
95
	}
96
}
97