require_once 'CRM/Core/Page.php';
class CRM_Memberdashboard_Page_Communications extends CRM_Core_Page {
+ function contactId() {
+ return CRM_Core_Session::singleton()->get('userID');
+ }
+
+ function loadContact() {
+ return civicrm_api3('contact', 'getsingle', array(
+ 'id' => $this->contactId()
+ ));
+ }
+
+ function isPOST() {
+ return $_SERVER['REQUEST_METHOD'] == 'POST';
+ }
+
+ function postProcess($params) {
+ // Update member's preferred mail format (plain text, HTML)
+ $key = 'preferred_mail_format';
+ $value = $params[$key];
+
+ civicrm_api3('contact', 'create', array(
+ 'id' => $this->contactId(),
+ $key => $value
+ ));
+ }
+
function run() {
+ // Handle POST requests to update email preferences.
+ if($this->isPOST()) {
+ $this->postProcess($_POST);
+ }
+
$helper = new CRM_Memberdashboard_Page_ComponentHelper(array('CiviEvent'));
$helper->run();
$this->assign('dashboardElements', $helper->buildDashboardElements());
+
$gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact();
- $gContact->run();
+ $gContact->browse();
+
+ $this->assign('contact', $this->loadContact());
+ $this->assign('mailFormats', array('Both', 'HTML', 'Text'));
CRM_Utils_System::setTitle('Communications');
{include file="CRM/Contact/Page/View/UserDashBoard/GroupContact.tpl"}
</div>
+<div>
+ <div class="header-dark">
+ {ts}Email Preferences{/ts}
+ </div>
+
+ <form method="post" action="{crmURL p='/civicrm/member-dashboard/communications'}">
+ <div class="form-item">
+ <label for="preferred_mail_format">Preferred Email Format</label>
+ <select name="preferred_mail_format">
+ {foreach from=$mailFormats item=format}
+ <option
+ {if $contact.preferred_mail_format eq $format}
+ selected="selected"
+ {/if}
+ value="{$format}">
+ {$format}
+ </option>
+ {/foreach}
+ </select>
+ <input type="submit" value="Save"/>
+ </div>
+ </form>
+</div>
+
{include file="CRM/Memberdashboard/Page/DashboardElement.tpl"
element=$dashboardElements.CiviEvent }