Remove all eval instances where eval is being used to instantiate a new object using...
[civicrm-core.git] / CRM / Contact / Form / Search / Custom.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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 */
35class CRM_Contact_Form_Search_Custom extends CRM_Contact_Form_Search {
36
37 protected $_customClass = NULL;
38
39 public function preProcess() {
40 $this->set('searchFormName', 'Custom');
41
42 $this->set('context', 'custom');
43
44 $csID = CRM_Utils_Request::retrieve('csid', 'Integer', $this);
45 $ssID = CRM_Utils_Request::retrieve('ssID', 'Integer', $this);
46 $gID = CRM_Utils_Request::retrieve('gid', 'Integer', $this);
47
48 list($this->_customSearchID,
49 $this->_customSearchClass,
50 $formValues
51 ) = CRM_Contact_BAO_SearchCustom::details($csID, $ssID, $gID);
52
53 if (!$this->_customSearchID) {
54 CRM_Core_Error::fatal('Could not get details for custom search.');
55 }
56
57 if (!empty($formValues)) {
58 $this->_formValues = $formValues;
59 }
60
61 // set breadcrumb to return to Custom Search listings page
62 $breadCrumb = array(array('title' => ts('Custom Searches'),
63 'url' => CRM_Utils_System::url('civicrm/contact/search/custom/list',
64 'reset=1'
65 ),
66 ));
67 CRM_Utils_System::appendBreadCrumb($breadCrumb);
68
69 // use the custom selector
70 self::$_selectorName = 'CRM_Contact_Selector_Custom';
71
72 $this->set('customSearchID', $this->_customSearchID);
73 $this->set('customSearchClass', $this->_customSearchClass);
74
75 parent::preProcess();
76
77 // instantiate the new class
4d5c2eb5 78 $this->_customClass = new $this->_customSearchClass( $this->_formValues );
6a488035
TO
79 }
80
81 function setDefaultValues() {
82 if (method_exists($this->_customSearchClass, 'setDefaultValues')) {
83 return $this->_customClass->setDefaultValues();
84 }
85 return $this->_formValues;
86 }
87
88 function buildQuickForm() {
89 $this->_customClass->buildForm($this);
90
91 parent::buildQuickForm();
92 }
93
94 function getTemplateFileName() {
95
96 $ext = CRM_Extension_System::singleton()->getMapper();
97
98 if ($ext->isExtensionClass(CRM_Utils_System::getClassName($this->_customClass))) {
99 $fileName = $ext->getTemplatePath(CRM_Utils_System::getClassName($this->_customClass)) . '/' . $ext->getTemplateName(CRM_Utils_System::getClassName($this->_customClass));
100 }
101 else {
102 $fileName = $this->_customClass->templateFile();
103 }
104
105 return $fileName ? $fileName : parent::getTemplateFileName();
106 }
107
108 function postProcess() {
109 $this->set('isAdvanced', '3');
110 $this->set('isCustom', '1');
111
112 // get user submitted values
113 // get it from controller only if form has been submitted, else preProcess has set this
114 if (!empty($_POST)) {
115 $this->_formValues = $this->controller->exportValues($this->_name);
116
117 $this->_formValues['customSearchID'] = $this->_customSearchID;
118 $this->_formValues['customSearchClass'] = $this->_customSearchClass;
119 }
120
121 //use the custom selector
122 self::$_selectorName = 'CRM_Contact_Selector_Custom';
123
124 parent::postProcess();
125 }
126
127 public function getTitle() {
128 return ts('Custom Search');
129 }
130}
131