_section) { return; } // Check role based permission. $instanceID = $form->getVar('_id'); if ($instanceID && !CRM_Report_Utils_Report::isInstanceGroupRoleAllowed($instanceID)) { $url = CRM_Utils_System::url('civicrm/report/list', 'reset=1'); CRM_Core_Error::statusBounce(ts('You do not have permission to access this report.'), $url ); } $attributes = CRM_Core_DAO::getAttribute('CRM_Report_DAO_ReportInstance'); $form->add('text', 'title', ts('Report Title'), $attributes['title'] ); $form->add('text', 'description', ts('Report Description'), $attributes['description'] ); $form->add('text', 'email_subject', ts('Subject'), $attributes['email_subject'] ); $form->add('text', 'email_to', ts('To'), $attributes['email_to'] ); $form->add('text', 'email_cc', ts('CC'), $attributes['email_subject'] ); $form->add('number', 'row_count', ts('Limit Dashboard Results'), ['class' => 'four', 'min' => 1] ); $form->add('textarea', 'report_header', ts('Report Header'), $attributes['header'] ); $form->add('textarea', 'report_footer', ts('Report Footer'), $attributes['footer'] ); $form->addElement('checkbox', 'is_navigation', ts('Include Report in Navigation Menu?'), NULL, ['onclick' => "return showHideByValue('is_navigation','','navigation_menu','table-row','radio',false);"] ); $form->addElement('select', 'view_mode', ts('Configure link to...'), [ 'view' => ts('View Results'), 'criteria' => ts('Show Criteria'), ]); $form->addElement('checkbox', 'addToDashboard', ts('Available for Dashboard?')); $form->add('number', 'cache_minutes', ts('Cache dashlet for'), ['class' => 'four', 'min' => 1]); $form->addElement('checkbox', 'add_to_my_reports', ts('Add to My Reports?'), NULL); $form->addElement('checkbox', 'is_reserved', ts('Reserved Report?')); if (!CRM_Core_Permission::check('administer reserved reports')) { $form->freeze('is_reserved'); } $getPerms = \Civi\Api4\Permission::get(0) ->addWhere('is_active', '=', 1) ->addWhere('group', 'IN', ['civicrm', 'cms', 'const']) ->setOrderBy(['title' => 'ASC']) ->execute(); $form->addElement('select', 'permission', ts('Permission'), // FIXME: Historically, CiviReport hard-coded an extra '0' option. This should change to the more general ALWAYS_ALLOW_PERMISSION (but may require testing/migration). ['0' => ts('Everyone (includes anonymous)')] + array_combine($getPerms->column('name'), $getPerms->column('title')), ['class' => 'crm-select2'] ); // prepare user_roles to save as names not as ids if ($user_roles = CRM_Core_Config::singleton()->userSystem->getRoleNames()) { $grouprole = $form->addElement('advmultiselect', 'grouprole', ts('ACL Group/Role'), $user_roles, [ 'size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect', ] ); $grouprole->setButtonAttributes('add', ['value' => ts('Add >>')]); $grouprole->setButtonAttributes('remove', ['value' => ts('<< Remove')]); } // navigation field $parentMenu = CRM_Core_BAO_Navigation::getNavigationList(); $form->add('select', 'parent_id', ts('Parent Menu'), ['' => ts('- select -')] + $parentMenu); // For now we only providing drilldown for one primary detail report only. In future this could be multiple reports foreach ($form->_drilldownReport as $reportUrl => $drillLabel) { $instanceList = CRM_Report_Utils_Report::getInstanceList($reportUrl); if (count($instanceList) > 1) { $form->add('select', 'drilldown_id', $drillLabel, ['' => ts('- select -')] + $instanceList); } break; } $form->addButtons([ [ 'type' => 'submit', 'name' => ts('Save Report'), 'isDefault' => TRUE, ], [ 'type' => 'cancel', 'name' => ts('Cancel'), ], ]); $form->addFormRule(['CRM_Report_Form_Instance', 'formRule'], $form); } /** * Add form rules. * * @param array $fields * @param array $errors * @param CRM_Report_Form_Instance $self * * @return array|bool */ public static function formRule($fields, $errors, $self) { // Validate both the "next" and "save" buttons for creating/updating a report. $nextButton = $self->controller->getButtonName(); $saveButton = str_replace('_next', '_save', $nextButton); $clickedButton = $self->getVar('_instanceButtonName'); $errors = []; if ($clickedButton == $nextButton || $clickedButton == $saveButton) { if (empty($fields['title'])) { $errors['title'] = ts('Title is a required field.'); $self->assign('instanceFormError', TRUE); } } return empty($errors) ? TRUE : $errors; } /** * Set default values. * * @param CRM_Core_Form $form * @param array $defaults */ public static function setDefaultValues(&$form, &$defaults) { // we should not build form elements in dashlet mode. if (!empty($form->_section)) { return; } $instanceID = $form->getVar('_id'); $navigationDefaults = []; if (!isset($defaults['permission'])) { $defaults['permission'] = 'access CiviReport'; } $userFrameworkResourceURL = CRM_Core_Config::singleton()->userFrameworkResourceURL; // Add a special region for the default HTML header of printed reports. It // won't affect reports with customized headers, just ones with the default. $printHeaderRegion = CRM_Core_Region::instance('default-report-header', FALSE); $htmlHeader = ($printHeaderRegion) ? $printHeaderRegion->render('', FALSE) : ''; $defaults['report_header'] = $report_header = "