Merge pull request #23609 from briennekordis/leading_zero_fix
[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 $expectedKeys = ['server', 'username', 'localpart', 'domain', 'return_path', 'protocol', 'source', 'port', 'is_ssl'];
109 foreach ($allMailSettings as $key => $allMailSetting) {
110 // make sure they are there to prevent smarty notices.
111 $allMailSettings[$key] = array_merge(array_fill_keys($expectedKeys, NULL), $allMailSetting);
112 }
113 $this->assign('rows', $allMailSettings);
114
115 $setupActions = CRM_Core_BAO_MailSettings::getSetupActions();
116 if (count($setupActions) > 1 || !isset($setupActions['standard'])) {
117 $this->assign('setupActions', $setupActions);
118 }
119 }
120
121 /**
122 * Get name of edit form.
123 *
124 * @return string
125 * Classname of edit form.
126 */
127 public function editForm() {
128 return 'CRM_Admin_Form_MailSettings';
129 }
130
131 /**
132 * Get edit form name.
133 *
134 * @return string
135 * name of this page.
136 */
137 public function editName() {
138 return 'Mail Settings';
139 }
140
141 /**
142 * Get user context.
143 *
144 * @param null $mode
145 *
146 * @return string
147 * user context.
148 */
149 public function userContext($mode = NULL) {
150 return 'civicrm/admin/mailSettings';
151 }
152
153 }