communications: Add email preferences.
[org.fsf.memberdashboard.git] / CRM / Memberdashboard / Page / Communications.php
1 <?php
2 /**
3 * FSF Member Dashboard
4 * Copyright © 2014 Free Software Foundation, Inc.
5 *
6 * This file is a part of FSF Member Dashboard.
7 *
8 * FSF Member Dashboard is free software; you can copy, modify, and
9 * distribute it under the terms of the GNU Affero General Public
10 * License Version 3, 19 November 2007 and the CiviCRM Licensing
11 * Exception.
12 *
13 * FSF Member Dashboard is distributed in the hope that it will be
14 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with FSF Member Dashboard. If not, see
20 * <http://www.gnu.org/licenses/>.
21 */
22
23 require_once 'CRM/Core/Page.php';
24
25 class CRM_Memberdashboard_Page_Communications extends CRM_Core_Page {
26 function contactId() {
27 return CRM_Core_Session::singleton()->get('userID');
28 }
29
30 function loadContact() {
31 return civicrm_api3('contact', 'getsingle', array(
32 'id' => $this->contactId()
33 ));
34 }
35
36 function isPOST() {
37 return $_SERVER['REQUEST_METHOD'] == 'POST';
38 }
39
40 function postProcess($params) {
41 // Update member's preferred mail format (plain text, HTML)
42 $key = 'preferred_mail_format';
43 $value = $params[$key];
44
45 civicrm_api3('contact', 'create', array(
46 'id' => $this->contactId(),
47 $key => $value
48 ));
49 }
50
51 function run() {
52 // Handle POST requests to update email preferences.
53 if($this->isPOST()) {
54 $this->postProcess($_POST);
55 }
56
57 $helper = new CRM_Memberdashboard_Page_ComponentHelper(array('CiviEvent'));
58 $helper->run();
59 $this->assign('dashboardElements', $helper->buildDashboardElements());
60
61 $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact();
62 $gContact->browse();
63
64 $this->assign('contact', $this->loadContact());
65 $this->assign('mailFormats', array('Both', 'HTML', 'Text'));
66
67 CRM_Utils_System::setTitle('Communications');
68
69 parent::run();
70 }
71 }