3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * This class provides the functionality to alter a privacy
38 * options for selected contacts
40 class CRM_Contact_Form_Task_AlterPreferences
extends CRM_Contact_Form_Task
{
43 * Build the form object
49 function buildQuickForm() {
50 // add select for preferences
52 $options = array(ts('Add Selected Options'), ts('Remove selected options'));
54 $this->addRadio('actionTypeOption', ts('actionTypeOption'), $options);
56 $privacyOptions = CRM_Core_SelectValues
::privacy();
58 foreach ($privacyOptions as $prefID => $prefName) {
59 $this->_prefElement
= &$this->addElement('checkbox', "pref[$prefID]", NULL, $prefName);
62 $this->addDefaultButtons(ts('Set Privacy Options'));
66 $this->addFormRule(array('CRM_Contact_Form_Task_AlterPreferences', 'formRule'));
70 * Set the default form values
74 * @return array the default array reference
76 function setDefaultValues() {
79 $defaults['actionTypeOption'] = 0;
84 * @param CRM_Core_Form $form
89 static function formRule($form, $rule) {
91 if (empty($form['pref']) && empty($form['contact_taglist'])) {
92 $errors['_qf_default'] = ts("Please select at least one privacy option.");
98 * Process the form after the input has been submitted and validated
104 public function postProcess() {
105 //get the submitted values in an array
106 $params = $this->controller
->exportValues($this->_name
);
108 $actionTypeOption = CRM_Utils_Array
::value('actionTypeOption', $params, NULL);
109 // If remove option has been selected set new privacy value to "false"
110 $privacyValueNew = empty($actionTypeOption);
112 // check if any privay option has been checked
113 if (!empty($params['pref'])) {
114 $privacyValues = $params['pref'];
116 foreach($this->_contactIds
as $contact_id) {
117 $contact = new CRM_Contact_BAO_Contact();
118 $contact->id
= $contact_id;
120 foreach($privacyValues as $privacy_key => $privacy_value) {
121 $contact->$privacy_key = $privacyValueNew;
127 $privacyOptions = CRM_Core_SelectValues
::privacy();
129 foreach($privacyValues as $privacy_key => $privacy_value) {
130 $label = $privacyOptions[$privacy_key];
131 $status[] = $privacyValueNew ?
ts("Added '%1'", array(1 => $label)) : ts("Removed '%1'", array(1 => $label));
134 $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
136 $title = ts('%1 Contacts Updated', array(1 => $count));
139 $name = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contact_id, 'display_name');
140 $title = ts('%1 Updated', array(1 => $name));
143 CRM_Core_Session
::setStatus($status, $title, 'success');