Merge pull request #16574 from civicrm/5.23
[civicrm-core.git] / CRM / Admin / Page / MailSettings.php
CommitLineData
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 */
21class 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
87 $mailSetting->protocol = CRM_Utils_Array::value($mailSetting->protocol, $allProtocols);
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 }
108
109 $this->assign('rows', $allMailSettings);
110 }
111
112 /**
eceb18cc 113 * Get name of edit form.
6a488035 114 *
a6c01b45
CW
115 * @return string
116 * Classname of edit form.
6a488035 117 */
00be9182 118 public function editForm() {
6a488035
TO
119 return 'CRM_Admin_Form_MailSettings';
120 }
121
122 /**
eceb18cc 123 * Get edit form name.
6a488035 124 *
a6c01b45
CW
125 * @return string
126 * name of this page.
6a488035 127 */
00be9182 128 public function editName() {
6a488035
TO
129 return 'Mail Settings';
130 }
131
132 /**
133 * Get user context.
134 *
da6b46f4
EM
135 * @param null $mode
136 *
a6c01b45
CW
137 * @return string
138 * user context.
6a488035 139 */
00be9182 140 public function userContext($mode = NULL) {
6a488035
TO
141 return 'civicrm/admin/mailSettings';
142 }
96025800 143
6a488035 144}