3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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-2016
35 class CRM_Report_Form_Register
extends CRM_Core_Form
{
37 protected $_values = NULL;
39 public function preProcess() {
40 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
41 $this->_id
= CRM_Utils_Request
::retrieve('id', 'String', $this, FALSE);
43 CRM_Utils_System
::setTitle(ts('Report Template'));
45 if ($this->_action
& CRM_Core_Action
::DELETE
) {
49 $this->_opID
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup',
50 'report_template', 'id', 'name'
53 $instanceInfo = array();
57 * This virtual function is used to set the default values of.
58 * various form elements
63 * reference to the array of default values
65 public function setDefaultValues() {
67 if ($this->_action
& CRM_Core_Action
::DELETE
) {
71 $params = array('id' => $this->_id
);
73 CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_OptionValue', $params, $defaults);
76 $defaults['weight'] = CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue',
77 array('option_group_id' => $this->_opID
)
83 public function buildQuickForm() {
84 if ($this->_action
& CRM_Core_Action
::DELETE
) {
85 $this->addButtons(array(
88 'name' => ts('Delete'),
89 'spacing' => ' ',
94 'name' => ts('Cancel'),
101 $this->add('text', 'label', ts('Title'), array('size' => 40), TRUE);
102 $this->add('text', 'value', ts('URL'), array('size' => 40), TRUE);
103 $this->add('text', 'name', ts('Class'), array('size' => 40), TRUE);
104 $element = $this->add('text', 'weight', ts('Order'), array('size' => 4), TRUE);
105 // $element->freeze( );
106 $this->add('text', 'description', ts('Description'), array('size' => 40), TRUE);
108 $this->add('checkbox', 'is_active', ts('Enabled?'));
109 $this->_components
= CRM_Core_Component
::getComponents();
110 //unset the report component
111 unset($this->_components
['CiviReport']);
113 $components = array();
114 foreach ($this->_components
as $name => $object) {
115 $components[$object->componentID
] = $object->info
['translatedName'];
118 $this->add('select', 'component_id', ts('Component'), array('' => ts('Contact')) +
$components);
120 $this->addButtons(array(
123 'name' => ts('Save'),
124 'spacing' => ' ',
129 'name' => ts('Cancel'),
133 $this->addFormRule(array('CRM_Report_Form_Register', 'formRule'), $this);
143 public static function formRule($fields, $files, $self) {
146 $reportUrl = new CRM_Core_DAO_OptionValue();
147 $reportUrl->option_group_id
= $self->_opID
;
148 $reportUrl->value
= $fields['value'];
150 if ($reportUrl->find(TRUE) && $self->_id
!= $reportUrl->id
) {
151 $errors['value'] = ts('Url already exists in Database.');
153 if ($reportUrl->name
== $fields['name']) {
158 $reportClass = new CRM_Core_DAO_OptionValue();
159 $reportClass->option_group_id
= $self->_opID
;
160 $reportClass->name
= $fields['name'];
161 if ($reportClass->find(TRUE) && $self->_id
!= $reportClass->id
) {
167 $errors['name'] = ts('Class already exists in Database.');
173 * Process the form submission.
178 public function postProcess() {
179 if ($this->_action
& CRM_Core_Action
::DELETE
) {
181 if (CRM_Core_BAO_OptionValue
::del($this->_id
)) {
182 CRM_Core_Session
::setStatus(ts('Selected %1 Report has been deleted.', array(1 => $this->_GName
)), ts('Record Deleted'), 'success');
183 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/report/options/report_template', "reset=1"));
186 CRM_Core_Session
::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName
)), '', 'info');
187 CRM_Utils_Weight
::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
191 // get the submitted form values.
192 $params = $this->controller
->exportValues($this->_name
);
195 $groupParams = array('name' => ('report_template'));
196 $optionValue = CRM_Core_OptionValue
::addOptionValue($params, $groupParams, $this->_action
, $this->_id
);
197 CRM_Core_Session
::setStatus(ts('The %1 \'%2\' has been saved.', array(
198 1 => 'Report Template',
199 2 => $optionValue->label
,
200 )), ts('Saved'), 'success');
201 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/report/options/report_template', "reset=1"));