3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
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'
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 = ['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 ['option_group_id' => $this->_opID
]
83 public function buildQuickForm() {
84 if ($this->_action
& CRM_Core_Action
::DELETE
) {
88 'name' => ts('Delete'),
89 'spacing' => ' ',
94 'name' => ts('Cancel'),
100 $this->add('text', 'label', ts('Title'), ['size' => 40], TRUE);
101 $this->add('text', 'value', ts('URL'), ['size' => 40], TRUE);
102 $this->add('text', 'name', ts('Class'), ['size' => 40], TRUE);
103 $element = $this->add('number', 'weight', ts('Order'), ['size' => 4], TRUE);
104 // $element->freeze( );
105 $this->add('text', 'description', ts('Description'), ['size' => 40], TRUE);
107 $this->add('checkbox', 'is_active', ts('Enabled?'));
108 $this->_components
= CRM_Core_Component
::getComponents();
109 //unset the report component
110 unset($this->_components
['CiviReport']);
113 foreach ($this->_components
as $name => $object) {
114 $components[$object->componentID
] = $object->info
['translatedName'];
117 $this->add('select', 'component_id', ts('Component'), ['' => ts('Contact')] +
$components);
122 'name' => ts('Save'),
123 'spacing' => ' ',
128 'name' => ts('Cancel'),
131 $this->addFormRule(['CRM_Report_Form_Register', 'formRule'], $this);
141 public static function formRule($fields, $files, $self) {
144 $reportUrl = new CRM_Core_DAO_OptionValue();
145 $reportUrl->option_group_id
= $self->_opID
;
146 $reportUrl->value
= $fields['value'];
148 if ($reportUrl->find(TRUE) && $self->_id
!= $reportUrl->id
) {
149 $errors['value'] = ts('Url already exists in Database.');
151 if ($reportUrl->name
== $fields['name']) {
156 $reportClass = new CRM_Core_DAO_OptionValue();
157 $reportClass->option_group_id
= $self->_opID
;
158 $reportClass->name
= $fields['name'];
159 if ($reportClass->find(TRUE) && $self->_id
!= $reportClass->id
) {
165 $errors['name'] = ts('Class already exists in Database.');
171 * Process the form submission.
176 public function postProcess() {
177 if ($this->_action
& CRM_Core_Action
::DELETE
) {
179 if (CRM_Core_BAO_OptionValue
::del($this->_id
)) {
180 CRM_Core_Session
::setStatus(ts('Selected %1 Report has been deleted.', [1 => $this->_GName
]), ts('Record Deleted'), 'success');
181 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/report/options/report_template', "reset=1"));
184 CRM_Core_Session
::setStatus(ts('Selected %1 type has not been deleted.', [1 => $this->_GName
]), '', 'info');
185 CRM_Utils_Weight
::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
189 // get the submitted form values.
190 $params = $this->controller
->exportValues($this->_name
);
192 $optionValue = CRM_Core_OptionValue
::addOptionValue($params, 'report_template', $this->_action
, $this->_id
);
193 CRM_Core_Session
::setStatus(ts('The %1 \'%2\' has been saved.', [
194 1 => 'Report Template',
195 2 => $optionValue->label
,
196 ]), ts('Saved'), 'success');
197 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/report/options/report_template', "reset=1"));