4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2013
38 * This class provides the functionality to alter a privacy
39 * options for selected contacts
41 class CRM_Contact_Form_Task_AlterPreferences
extends CRM_Contact_Form_Task
{
50 function buildQuickForm() {
51 // add select for preferences
53 $options = array(ts('Add Selected Options'), ts('Remove selected options'));
55 $this->addRadio('actionTypeOption', ts('actionTypeOption'), $options);
57 $privacyOptions = CRM_Core_SelectValues
::privacy();
59 foreach ($privacyOptions as $prefID => $prefName) {
60 $this->_prefElement
= &$this->addElement('checkbox', "pref[$prefID]", NULL, $prefName);
63 $this->addDefaultButtons(ts('Set Privacy Options'));
67 $this->addFormRule(array('CRM_Contact_Form_Task_AlterPreferences', 'formRule'));
71 * Set the default form values
75 * @return array the default array reference
77 function setDefaultValues() {
80 $defaults['actionTypeOption'] = 0;
84 static function formRule($form, $rule) {
86 if (empty($form['pref']) && empty($form['contact_taglist'])) {
87 $errors['_qf_default'] = ts("Please select at least one privacy option.");
93 * process the form after the input has been submitted and validated
99 public function postProcess() {
100 //get the submitted values in an array
101 $params = $this->controller
->exportValues($this->_name
);
103 $actionTypeOption = CRM_Utils_Array
::value('actionTypeOption', $params, NULL);
104 // If remove option has been selected set new privacy value to "false"
105 $privacyValueNew = empty($actionTypeOption);
107 // check if any privay option has been checked
108 if (!empty($params['pref'])) {
109 $privacyValues = $params['pref'];
111 foreach($this->_contactIds
as $contact_id) {
112 $contact = new CRM_Contact_BAO_Contact();
113 $contact->id
= $contact_id;
115 foreach($privacyValues as $privacy_key => $privacy_value) {
116 $contact->$privacy_key = $privacyValueNew;
122 $privacyOptions = CRM_Core_SelectValues
::privacy();
124 foreach($privacyValues as $privacy_key => $privacy_value) {
125 $label = $privacyOptions[$privacy_key];
126 $status[] = $privacyValueNew ?
ts("Added '%1'", array(1 => $label)) : ts("Removed '%1'", array(1 => $label));
129 $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
131 $title = ts('%1 Contacts Updated', array(1 => $count));
134 $name = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contact_id, 'display_name');
135 $title = ts('%1 Updated', array(1 => $name));
138 CRM_Core_Session
::setStatus($status, $title, 'success');