Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
ce064e4f | 19 | * Page for displaying list of Mail account settings. |
6a488035 TO |
20 | */ |
21 | class CRM_Admin_Page_MailSettings extends CRM_Core_Page_Basic { | |
22 | ||
96f50de2 | 23 | public $useLivePageJS = TRUE; |
da6b46f4 | 24 | |
6a488035 | 25 | /** |
eceb18cc | 26 | * The action links that we need to display for the browse screen. |
6a488035 TO |
27 | * |
28 | * @var array | |
6a488035 | 29 | */ |
62d3ee27 | 30 | public static $_links = NULL; |
6a488035 TO |
31 | |
32 | /** | |
eceb18cc | 33 | * Get BAO Name. |
6a488035 | 34 | * |
a6c01b45 CW |
35 | * @return string |
36 | * Classname of BAO. | |
6a488035 | 37 | */ |
00be9182 | 38 | public function getBAOName() { |
6a488035 TO |
39 | return 'CRM_Core_BAO_MailSettings'; |
40 | } | |
41 | ||
42 | /** | |
eceb18cc | 43 | * Get action Links. |
6a488035 | 44 | * |
a6c01b45 CW |
45 | * @return array |
46 | * (reference) of action links | |
6a488035 | 47 | */ |
00be9182 | 48 | public function &links() { |
6a488035 TO |
49 | if (!(self::$_links)) { |
50 | // helper variable for nicer formatting | |
be2fb01f CW |
51 | self::$_links = [ |
52 | CRM_Core_Action::UPDATE => [ | |
6a488035 TO |
53 | 'name' => ts('Edit'), |
54 | 'url' => 'civicrm/admin/mailSettings', | |
55 | 'qs' => 'action=update&id=%%id%%&reset=1', | |
56 | 'title' => ts('Edit Mail Settings'), | |
be2fb01f CW |
57 | ], |
58 | CRM_Core_Action::DELETE => [ | |
6a488035 TO |
59 | 'name' => ts('Delete'), |
60 | 'url' => 'civicrm/admin/mailSettings', | |
61 | 'qs' => 'action=delete&id=%%id%%', | |
62 | 'title' => ts('Delete Mail Settings'), | |
be2fb01f CW |
63 | ], |
64 | ]; | |
6a488035 TO |
65 | } |
66 | ||
67 | return self::$_links; | |
68 | } | |
69 | ||
70 | /** | |
71 | * Browse all mail settings. | |
6a488035 | 72 | */ |
00be9182 | 73 | public function browse() { |
6a488035 | 74 | //get all mail settings. |
be2fb01f | 75 | $allMailSettings = []; |
6a488035 TO |
76 | $mailSetting = new CRM_Core_DAO_MailSettings(); |
77 | ||
cbf48754 | 78 | $allProtocols = CRM_Core_PseudoConstant::get('CRM_Core_DAO_MailSettings', 'protocol'); |
6a488035 TO |
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 | |
9c1bc317 | 87 | $mailSetting->protocol = $allProtocols[$mailSetting->protocol] ?? NULL; |
6a488035 TO |
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, | |
be2fb01f | 100 | ['id' => $mailSetting->id], |
87dab4a4 AH |
101 | ts('more'), |
102 | FALSE, | |
103 | 'mailSetting.manage.action', | |
104 | 'MailSetting', | |
105 | $mailSetting->id | |
6a488035 TO |
106 | ); |
107 | } | |
bd3b004d EM |
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 | } | |
6a488035 | 113 | $this->assign('rows', $allMailSettings); |
5f68c8c8 TO |
114 | |
115 | $setupActions = CRM_Core_BAO_MailSettings::getSetupActions(); | |
116 | if (count($setupActions) > 1 || !isset($setupActions['standard'])) { | |
117 | $this->assign('setupActions', $setupActions); | |
118 | } | |
6a488035 TO |
119 | } |
120 | ||
121 | /** | |
eceb18cc | 122 | * Get name of edit form. |
6a488035 | 123 | * |
a6c01b45 CW |
124 | * @return string |
125 | * Classname of edit form. | |
6a488035 | 126 | */ |
00be9182 | 127 | public function editForm() { |
6a488035 TO |
128 | return 'CRM_Admin_Form_MailSettings'; |
129 | } | |
130 | ||
131 | /** | |
eceb18cc | 132 | * Get edit form name. |
6a488035 | 133 | * |
a6c01b45 CW |
134 | * @return string |
135 | * name of this page. | |
6a488035 | 136 | */ |
00be9182 | 137 | public function editName() { |
6a488035 TO |
138 | return 'Mail Settings'; |
139 | } | |
140 | ||
141 | /** | |
142 | * Get user context. | |
143 | * | |
da6b46f4 EM |
144 | * @param null $mode |
145 | * | |
a6c01b45 CW |
146 | * @return string |
147 | * user context. | |
6a488035 | 148 | */ |
00be9182 | 149 | public function userContext($mode = NULL) { |
6a488035 TO |
150 | return 'civicrm/admin/mailSettings'; |
151 | } | |
96025800 | 152 | |
6a488035 | 153 | } |