CRM-14856 - CRM_Profile_Form - Load postURL and add_to_group from DB (instead of...
[civicrm-core.git] / CRM / Profile / Form / Search.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
32 * $Id$
33 *
34 */
35
36 /**
37 * This class generates form components generic to all the contact types.
38 *
39 * It delegates the work to lower level subclasses and integrates the changes
40 * back in. It also uses a lot of functionality with the CRM API's, so any change
41 * made here could potentially affect the API etc. Be careful, be aware, use unit tests.
42 *
43 */
44 class CRM_Profile_Form_Search extends CRM_Profile_Form {
45
46 /**
47 * pre processing work done here.
48 *
49 * @param
50 *
51 * @return void
52 *
53 * @access public
54 *
55 */
56 function preProcess() {
57 $this->_mode = CRM_Profile_Form::MODE_SEARCH;
58 parent::preProcess();
59 }
60
61 /**
62 * Set the default form values
63 *
64 * @access protected
65 *
66 * @return array the default array reference
67 */
68 function setDefaultValues() {
69 $defaults = array();
70 // note we intentionally overwrite value since we use it as defaults
71 // and its all pass by value
72 // we need to figure out the type, so we can either set an array element
73 // or a scalar -- FIX ME sometime please
74 foreach ($_GET as $key => $value) {
75 if (substr($key, 0, 7) == 'custom_' || $key == "preferred_communication_method") {
76 if (strpos($value, CRM_Core_DAO::VALUE_SEPARATOR) !== FALSE) {
77 $v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
78 $value = array();
79 foreach ($v as $item) {
80 if ($item) {
81 $value[$item] = $item;
82 }
83 }
84 }
85 }
86 elseif ($key == 'group' || $key == 'tag') {
87 $v = explode(',', $value);
88 $value = array();
89 foreach ($v as $item) {
90 $value[$item] = 1;
91 }
92 }
93 elseif (in_array($key, array(
94 'birth_date', 'deceased_date'))) {
95 list($value) = CRM_Utils_Date::setDateDefaults($value);
96 }
97
98 $defaults[$key] = $value;
99 }
100 return $defaults;
101 }
102
103 /**
104 * Function to actually build the form
105 *
106 * @return void
107 * @access public
108 */
109 public function buildQuickForm() {
110 // Is proximity search enabled for this profile?
111 $proxSearch = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup',
112 $this->get('gid'),
113 'is_proximity_search', 'id'
114 );
115 if ($proxSearch) {
116 CRM_Contact_Form_Task_ProximityCommon::buildQuickForm($this, $proxSearch);
117 }
118
119 $this->addButtons(array(
120 array(
121 'type' => 'refresh',
122 'name' => ts('Search'),
123 'isDefault' => TRUE,
124 ),
125 ));
126
127 parent::buildQuickForm();
128 }
129
130 /**
131 *
132 *
133 * @access public
134 *
135 * @return void
136 */
137 public function postProcess() {}
138 }
139