Merge pull request #12790 from alifrumin/core362
[civicrm-core.git] / CRM / Admin / Page / MailSettings.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2018
32 */
33
34 /**
35 * Page for displaying list of Mail account settings.
36 */
37 class CRM_Admin_Page_MailSettings extends CRM_Core_Page_Basic {
38
39 public $useLivePageJS = TRUE;
40
41 /**
42 * The action links that we need to display for the browse screen.
43 *
44 * @var array
45 */
46 static $_links = NULL;
47
48 /**
49 * Get BAO Name.
50 *
51 * @return string
52 * Classname of BAO.
53 */
54 public function getBAOName() {
55 return 'CRM_Core_BAO_MailSettings';
56 }
57
58 /**
59 * Get action Links.
60 *
61 * @return array
62 * (reference) of action links
63 */
64 public function &links() {
65 if (!(self::$_links)) {
66 // helper variable for nicer formatting
67 self::$_links = array(
68 CRM_Core_Action::UPDATE => array(
69 'name' => ts('Edit'),
70 'url' => 'civicrm/admin/mailSettings',
71 'qs' => 'action=update&id=%%id%%&reset=1',
72 'title' => ts('Edit Mail Settings'),
73 ),
74 CRM_Core_Action::DELETE => array(
75 'name' => ts('Delete'),
76 'url' => 'civicrm/admin/mailSettings',
77 'qs' => 'action=delete&id=%%id%%',
78 'title' => ts('Delete Mail Settings'),
79 ),
80 );
81 }
82
83 return self::$_links;
84 }
85
86 /**
87 * Browse all mail settings.
88 */
89 public function browse() {
90 //get all mail settings.
91 $allMailSettings = array();
92 $mailSetting = new CRM_Core_DAO_MailSettings();
93
94 $allProtocols = CRM_Core_PseudoConstant::get('CRM_Core_DAO_MailSettings', 'protocol');
95
96 //multi-domain support for mail settings. CRM-5244
97 $mailSetting->domain_id = CRM_Core_Config::domainID();
98
99 //find all mail settings.
100 $mailSetting->find();
101 while ($mailSetting->fetch()) {
102 //replace protocol value with name
103 $mailSetting->protocol = CRM_Utils_Array::value($mailSetting->protocol, $allProtocols);
104 CRM_Core_DAO::storeValues($mailSetting, $allMailSettings[$mailSetting->id]);
105
106 //form all action links
107 $action = array_sum(array_keys($this->links()));
108
109 // disallow the DELETE action for the default set of settings
110 if ($mailSetting->is_default) {
111 $action &= ~CRM_Core_Action::DELETE;
112 }
113
114 //add action links.
115 $allMailSettings[$mailSetting->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
116 array('id' => $mailSetting->id),
117 ts('more'),
118 FALSE,
119 'mailSetting.manage.action',
120 'MailSetting',
121 $mailSetting->id
122 );
123 }
124
125 $this->assign('rows', $allMailSettings);
126 }
127
128 /**
129 * Get name of edit form.
130 *
131 * @return string
132 * Classname of edit form.
133 */
134 public function editForm() {
135 return 'CRM_Admin_Form_MailSettings';
136 }
137
138 /**
139 * Get edit form name.
140 *
141 * @return string
142 * name of this page.
143 */
144 public function editName() {
145 return 'Mail Settings';
146 }
147
148 /**
149 * Get user context.
150 *
151 * @param null $mode
152 *
153 * @return string
154 * user context.
155 */
156 public function userContext($mode = NULL) {
157 return 'civicrm/admin/mailSettings';
158 }
159
160 }