5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
33 * @copyright CiviCRM LLC (c) 2004-2013
37 class CRM_Report_Form_Register
extends CRM_Core_Form
{
39 protected $_values = NULL;
41 public function preProcess() {
42 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
43 $this->_id
= CRM_Utils_Request
::retrieve('id', 'String', $this, FALSE);
45 CRM_Utils_System
::setTitle(ts('Report Template'));
47 if ($this->_action
& CRM_Core_Action
::DELETE
) {
51 // crm_core_error::debug("$this->_actions", $this->_action);
52 $this->_opID
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup',
53 'report_template', 'id', 'name'
56 $instanceInfo = array();
59 function setDefaultValues() {
61 if ($this->_action
& CRM_Core_Action
::DELETE
) {
65 $params = array('id' => $this->_id
);
67 CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_OptionValue', $params, $defaults);
70 $defaults['weight'] = CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue',
71 array('option_group_id' => $this->_opID
)
77 public function buildQuickForm() {
78 if ($this->_action
& CRM_Core_Action
::DELETE
) {
79 $this->addButtons(array(
82 'name' => ts('Delete'),
83 'spacing' => ' ',
88 'name' => ts('Cancel'),
95 $this->add('text', 'label', ts('Title'), array('size' => 40), TRUE);
96 $this->add('text', 'value', ts('URL'), array('size' => 40), TRUE);
97 $this->add('text', 'name', ts('Class'), array('size' => 40), TRUE);
98 $element = $this->add('text', 'weight', ts('Weight'), array('size' => 4), TRUE);
99 // $element->freeze( );
100 $this->add('text', 'description', ts('Description'), array('size' => 40), TRUE);
102 $this->add('checkbox', 'is_active', ts('Enabled?'));
103 $this->_components
= CRM_Core_Component
::getComponents();
104 //unset the report component
105 unset($this->_components
['CiviReport']);
107 $components = array();
108 foreach ($this->_components
as $name => $object) {
109 $components[$object->componentID
] = $object->info
['translatedName'];
112 $this->add('select', 'component_id', ts('Component'), array('' => ts('Contact')) +
$components);
114 $this->addButtons(array(
117 'name' => ts('Save'),
118 'spacing' => ' ',
123 'name' => ts('Cancel'),
127 $this->addFormRule(array('CRM_Report_Form_Register', 'formRule'), $this);
130 static function formRule($fields, $files, $self) {
133 $reportUrl = new CRM_Core_DAO_OptionValue();
134 $reportUrl->option_group_id
= $self->_opID
;
135 $reportUrl->value
= $fields['value'];
137 if ($reportUrl->find(TRUE) && $self->_id
!= $reportUrl->id
) {
138 $errors['value'] = ts('Url already exists in Database.');
140 if ($reportUrl->name
== $fields['name']) {
145 $reportClass = new CRM_Core_DAO_OptionValue();
146 $reportClass->option_group_id
= $self->_opID
;
147 $reportClass->name
= $fields['name'];
148 if ($reportClass->find(TRUE) && $self->_id
!= $reportClass->id
) {
154 $errors['name'] = ts('Class already exists in Database.');
160 * Function to process the form
166 public function postProcess() {
167 if ($this->_action
& CRM_Core_Action
::DELETE
) {
169 if (CRM_Core_BAO_OptionValue
::del($this->_id
)) {
170 CRM_Core_Session
::setStatus(ts('Selected %1 Report has been deleted.', array(1 => $this->_GName
)), ts('Record Deleted'), 'success');
171 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/report/options/report_template', "reset=1"));
174 CRM_Core_Session
::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName
)), '', 'info');
175 CRM_Utils_Weight
::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
179 // get the submitted form values.
180 $params = $this->controller
->exportValues($this->_name
);
183 $groupParams = array('name' => ('report_template'));
184 $optionValue = CRM_Core_OptionValue
::addOptionValue($params, $groupParams, $this->_action
, $this->_id
);
185 CRM_Core_Session
::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => 'Report Template', 2 => $optionValue->label
)), ts('Saved'), 'success');
186 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/report/options/report_template', "reset=1"));