commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / CRM / Contribute / Form / Task / PickProfile.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
32 * $Id$
33 *
34 */
35
36 /**
37 * This class provides the functionality for batch profile update for contribution
38 */
39 class CRM_Contribute_Form_Task_PickProfile extends CRM_Contribute_Form_Task {
40
41 /**
42 * The title of the group
43 *
44 * @var string
45 */
46 protected $_title;
47
48 /**
49 * Maximum contributions that should be allowed to update
50 */
51 protected $_maxContributions = 100;
52
53 /**
54 * Variable to store redirect path
55 */
56 protected $_userContext;
57
58 /**
59 * Build all the data structures needed to build the form.
60 *
61 * @return void
62 */
63 public function preProcess() {
64 // initialize the task and row fields
65 parent::preProcess();
66 $session = CRM_Core_Session::singleton();
67 $this->_userContext = $session->readUserContext();
68
69 CRM_Utils_System::setTitle(ts('Batch Update Contributions Via Profile'));
70
71 $validate = FALSE;
72 //validations
73 if (count($this->_contributionIds) > $this->_maxContributions) {
74 CRM_Core_Session::setStatus(ts("The maximum number of contributions you can select for Batch Update is %1. You have selected %2. Please select fewer contributions from your search results and try again.", array(
75 1 => $this->_maxContributions,
76 2 => count($this->_contributionIds),
77 )), ts('Batch Update Error'), 'error');
78 $validate = TRUE;
79 }
80
81 // than redirect
82 if ($validate) {
83 CRM_Utils_System::redirect($this->_userContext);
84 }
85 }
86
87 /**
88 * Build the form object.
89 *
90 *
91 * @return void
92 */
93 public function buildQuickForm() {
94
95 $types = array('Contribution');
96 $profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE);
97
98 if (empty($profiles)) {
99 CRM_Core_Session::setStatus(ts("You will need to create a Profile containing the %1 fields you want to edit before you can use Batch Update via Profile. Navigate to Administer CiviCRM > Customize Data and Screens > CiviCRM Profile to configure a Profile. Consult the online Administrator documentation for more information.", array(1 => $types[0])), ts('Profile Required'), 'error');
100 CRM_Utils_System::redirect($this->_userContext);
101 }
102
103 $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'),
104 array(
105 '' => ts('- select profile -'),
106 ) + $profiles, TRUE
107 );
108 $this->addDefaultButtons(ts('Continue'));
109 }
110
111 /**
112 * Add local and global form rules.
113 *
114 *
115 * @return void
116 */
117 public function addRules() {
118 $this->addFormRule(array('CRM_Contribute_Form_Task_PickProfile', 'formRule'));
119 }
120
121 /**
122 * Global validation rules for the form.
123 *
124 * @param array $fields
125 * Posted values of the form.
126 *
127 * @return array
128 * list of errors to be posted back to the form
129 */
130 public static function formRule($fields) {
131 return TRUE;
132 }
133
134 /**
135 * Process the form after the input has been submitted and validated.
136 *
137 *
138 * @return void
139 */
140 public function postProcess() {
141 $params = $this->exportValues();
142
143 $this->set('ufGroupId', $params['uf_group_id']);
144
145 // also reset the batch page so it gets new values from the db
146 $this->controller->resetPage('Batch');
147 }
148
149 }