Merge pull request #20602 from ixiam/dev#PreserveActivityTabFilter
[civicrm-core.git] / CRM / Admin / Page / MailSettings.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Page for displaying list of Mail account settings.
20 */
21 class CRM_Admin_Page_MailSettings extends CRM_Core_Page_Basic {
22
23 public $useLivePageJS = TRUE;
24
25 /**
26 * The action links that we need to display for the browse screen.
27 *
28 * @var array
29 */
30 public static $_links = NULL;
31
32 /**
33 * Get BAO Name.
34 *
35 * @return string
36 * Classname of BAO.
37 */
38 public function getBAOName() {
39 return 'CRM_Core_BAO_MailSettings';
40 }
41
42 /**
43 * Get action Links.
44 *
45 * @return array
46 * (reference) of action links
47 */
48 public function &links() {
49 if (!(self::$_links)) {
50 // helper variable for nicer formatting
51 self::$_links = [
52 CRM_Core_Action::UPDATE => [
53 'name' => ts('Edit'),
54 'url' => 'civicrm/admin/mailSettings',
55 'qs' => 'action=update&id=%%id%%&reset=1',
56 'title' => ts('Edit Mail Settings'),
57 ],
58 CRM_Core_Action::DELETE => [
59 'name' => ts('Delete'),
60 'url' => 'civicrm/admin/mailSettings',
61 'qs' => 'action=delete&id=%%id%%',
62 'title' => ts('Delete Mail Settings'),
63 ],
64 ];
65 }
66
67 return self::$_links;
68 }
69
70 /**
71 * Browse all mail settings.
72 */
73 public function browse() {
74 //get all mail settings.
75 $allMailSettings = [];
76 $mailSetting = new CRM_Core_DAO_MailSettings();
77
78 $allProtocols = CRM_Core_PseudoConstant::get('CRM_Core_DAO_MailSettings', 'protocol');
79
80 //multi-domain support for mail settings. CRM-5244
81 $mailSetting->domain_id = CRM_Core_Config::domainID();
82
83 //find all mail settings.
84 $mailSetting->find();
85 while ($mailSetting->fetch()) {
86 //replace protocol value with name
87 $mailSetting->protocol = $allProtocols[$mailSetting->protocol] ?? NULL;
88 CRM_Core_DAO::storeValues($mailSetting, $allMailSettings[$mailSetting->id]);
89
90 //form all action links
91 $action = array_sum(array_keys($this->links()));
92
93 // disallow the DELETE action for the default set of settings
94 if ($mailSetting->is_default) {
95 $action &= ~CRM_Core_Action::DELETE;
96 }
97
98 //add action links.
99 $allMailSettings[$mailSetting->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
100 ['id' => $mailSetting->id],
101 ts('more'),
102 FALSE,
103 'mailSetting.manage.action',
104 'MailSetting',
105 $mailSetting->id
106 );
107 }
108
109 $this->assign('rows', $allMailSettings);
110
111 $setupActions = CRM_Core_BAO_MailSettings::getSetupActions();
112 if (count($setupActions) > 1 || !isset($setupActions['standard'])) {
113 $this->assign('setupActions', $setupActions);
114 }
115 }
116
117 /**
118 * Get name of edit form.
119 *
120 * @return string
121 * Classname of edit form.
122 */
123 public function editForm() {
124 return 'CRM_Admin_Form_MailSettings';
125 }
126
127 /**
128 * Get edit form name.
129 *
130 * @return string
131 * name of this page.
132 */
133 public function editName() {
134 return 'Mail Settings';
135 }
136
137 /**
138 * Get user context.
139 *
140 * @param null $mode
141 *
142 * @return string
143 * user context.
144 */
145 public function userContext($mode = NULL) {
146 return 'civicrm/admin/mailSettings';
147 }
148
149 }