/** * Run this page (figure out the action needed and perform it). */ public function run() { $instanceId = CRM_Report_Utils_Report::getInstanceID(); if (!$instanceId) { $instanceId = CRM_Report_Utils_Report::getInstanceIDForPath(); } if (is_numeric($instanceId)) { $instanceURL = CRM_Utils_System::url("civicrm/report/instance/{$instanceId}", 'reset=1'); CRM_Core_Session::singleton()->replaceUserContext($instanceURL); } $action = CRM_Utils_Request::retrieve('action', 'String', $this); $optionVal = CRM_Report_Utils_Report::getValueFromUrl($instanceId); $reportUrl = CRM_Utils_System::url('civicrm/report/list', "reset=1"); if ($action & CRM_Core_Action::DELETE) { if (!CRM_Core_Permission::check('administer Reports')) { $statusMessage = ts('You do not have permission to Delete Report.'); CRM_Core_Error::statusBounce($statusMessage, $reportUrl); } $navId = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_ReportInstance', $instanceId, 'navigation_id', 'id'); CRM_Report_BAO_ReportInstance::del($instanceId); //delete navigation if exists if ($navId) { CRM_Core_BAO_Navigation::processDelete($navId); CRM_Core_BAO_Navigation::resetNavigation(); } CRM_Core_Session::setStatus(ts('Selected report has been deleted.'), ts('Deleted'), 'success'); } else { $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value'); if (empty($templateInfo)) { CRM_Core_Error::statusBounce('You have tried to access a report that does not exist.'); } $extKey = strpos($templateInfo['name'], '.'); $reportClass = NULL; if ($extKey !== FALSE) { $ext = CRM_Extension_System::singleton()->getMapper(); $reportClass = $ext->keyToClass($templateInfo['name'], 'report'); $templateInfo['name'] = $reportClass; } if (strstr($templateInfo['name'], '_Form') || !is_null($reportClass)) { $instanceInfo = array(); CRM_Report_BAO_ReportInstance::retrieve(array('id' => $instanceId), $instanceInfo); if (!empty($instanceInfo['title'])) { CRM_Utils_System::setTitle($instanceInfo['title']); $this->assign('reportTitle', $instanceInfo['title']); } else { CRM_Utils_System::setTitle($templateInfo['label']); $this->assign('reportTitle', $templateInfo['label']); } $wrapper = new CRM_Utils_Wrapper(); return $wrapper->run($templateInfo['name'], NULL, NULL); } CRM_Core_Session::setStatus(ts('Could not find template for the instance.'), ts('Template Not Found'), 'error'); } return CRM_Utils_System::redirect($reportUrl); }
/** * YoteUp ProcessCounselor API * * @return array API result descriptor * @see civicrm_api3_create_success * @see civicrm_api3_create_error * @throws API_Exception */ function civicrm_api3_nrm_processcounselor($params) { // Get list of counselors $counsellorCount = civicrm_api3('Contact', 'getCount', array('contact_sub_type' => 'Counselors')); $counselorParams = array('contact_sub_type' => 'Counselors', 'return.email' => 1, 'return.custom_' . TERRITORY_COUNSELOR => 1, 'rowCount' => $counsellorCount); $counselors = civicrm_api3('Contact', 'get', $counselorParams); $ind = array(); $is_error = 0; $messages = array("Report Mail Triggered..."); if ($counselors['count'] >= 1) { $counselors = $counselors['values']; foreach ($counselors as $key => $value) { if (!empty($value['custom_' . TERRITORY_COUNSELOR])) { $ind[$key]['contact_id'] = $value['contact_id']; $ind[$key]['email'] = $value['email']; } } // Now email $instanceId = CRM_Utils_Array::value('instanceId', $params); $_REQUEST['instanceId'] = $instanceId; $_REQUEST['sendmail'] = CRM_Utils_Array::value('sendmail', $params, 1); // if cron is run from terminal --output is reserved, and therefore we would provide another name 'format' $_REQUEST['output'] = CRM_Utils_Array::value('format', $params, CRM_Utils_Array::value('output', $params, 'pdf')); $_REQUEST['reset'] = CRM_Utils_Array::value('reset', $params, 1); $optionVal = CRM_Report_Utils_Report::getValueFromUrl($instanceId); $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', $optionVal, 'value'); if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form')) { $obj = new CRM_Report_Page_Instance(); $instanceInfo = array(); CRM_Report_BAO_ReportInstance::retrieve(array('id' => $instanceId), $instanceInfo); if (!empty($instanceInfo['title'])) { $obj->assign('reportTitle', $instanceInfo['title']); } else { $obj->assign('reportTitle', $templateInfo['label']); } foreach ($ind as $key => $value) { $_REQUEST['email_to_send'] = $value['email']; $_GET['counsellor_id_value'] = $value['contact_id']; $wrapper = new CRM_Utils_Wrapper(); $arguments = array('urlToSession' => array(array('urlVar' => 'instanceId', 'type' => 'Positive', 'sessionVar' => 'instanceId', 'default' => 'null')), 'ignoreKey' => TRUE); $messages[] = $wrapper->run($templateInfo['name'], NULL, $arguments); } } } if ($is_error == 0) { return civicrm_api3_create_success(); } else { return civicrm_api3_create_error($messages); } }
/** * Function for find out whether to use logging schema entries for contact * summary, instead of normal log entries. * * @return int report id of Contact Logging Report (Summary) / false * @access public * @static */ static function useLoggingReport() { // first check if logging is enabled $config = CRM_Core_Config::singleton(); if (!$config->logging) { return FALSE; } $loggingSchema = new CRM_Logging_Schema(); if ($loggingSchema->isEnabled()) { $params = array('report_id' => 'logging/contact/summary'); $instance = array(); CRM_Report_BAO_ReportInstance::retrieve($params, $instance); if (!empty($instance) && (empty($instance['permission']) || !empty($instance['permission']) && CRM_Core_Permission::check($instance['permission']))) { return $instance['id']; } } return FALSE; }
static function processReport($params) { $instanceId = CRM_Utils_Array::value('instanceId', $params); // hack for now, CRM-8358 $_REQUEST['instanceId'] = $instanceId; $_REQUEST['sendmail'] = CRM_Utils_Array::value('sendmail', $params, 1); // if cron is run from terminal --output is reserved, and therefore we would provide another name 'format' $_REQUEST['output'] = CRM_Utils_Array::value('format', $params, CRM_Utils_Array::value('output', $params, 'pdf')); $_REQUEST['reset'] = CRM_Utils_Array::value('reset', $params, 1); $optionVal = self::getValueFromUrl($instanceId); $messages = array("Report Mail Triggered..."); $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', $optionVal, 'value'); $obj = new CRM_Report_Page_Instance(); $is_error = 0; if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form')) { $instanceInfo = array(); CRM_Report_BAO_ReportInstance::retrieve(array('id' => $instanceId), $instanceInfo); if (!empty($instanceInfo['title'])) { $obj->assign('reportTitle', $instanceInfo['title']); } else { $obj->assign('reportTitle', $templateInfo['label']); } $wrapper = new CRM_Utils_Wrapper(); $arguments = array('urlToSession' => array(array('urlVar' => 'instanceId', 'type' => 'Positive', 'sessionVar' => 'instanceId', 'default' => 'null')), 'ignoreKey' => TRUE); $messages[] = $wrapper->run($templateInfo['name'], NULL, $arguments); } else { $is_error = 1; if (!$instanceId) { $messages[] = 'Required parameter missing: instanceId'; } else { $messages[] = 'Did not find valid instance to execute'; } } $result = array('is_error' => $is_error, 'messages' => implode("\n", $messages)); return $result; }
/** * Post process function. * * @param CRM_Core_Form $form * @param bool $redirect */ public static function postProcess(&$form, $redirect = TRUE) { $params = $form->getVar('_params'); $instanceID = $form->getVar('_id'); if ($isNew = $form->getVar('_createNew')) { // set the report_id since base template is going to be same, and we going to unset $instanceID // which will make it difficult later on, to compute report_id $params['report_id'] = CRM_Report_Utils_Report::getValueFromUrl($instanceID); // Unset $instanceID so a new copy would be created. $instanceID = NULL; } $params['instance_id'] = $instanceID; if (!empty($params['is_navigation'])) { $params['navigation'] = $form->_navigation; } elseif ($instanceID) { // Delete navigation if exists. $navId = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_ReportInstance', $instanceID, 'navigation_id', 'id'); if ($navId) { CRM_Core_BAO_Navigation::processDelete($navId); CRM_Core_BAO_Navigation::resetNavigation(); } } // make a copy of params $formValues = $params; // unset params from $formValues that doesn't match with DB columns of instance tables, and also not required in form-values for sure $unsetFields = array('title', 'to_emails', 'cc_emails', 'header', 'footer', 'qfKey', 'id', '_qf_default', 'report_header', 'report_footer', 'grouprole'); foreach ($unsetFields as $field) { unset($formValues[$field]); } $view_mode = $formValues['view_mode']; // pass form_values as string $params['form_values'] = serialize($formValues); $instance = CRM_Report_BAO_ReportInstance::create($params); $form->set('id', $instance->id); if ($instanceID && !$isNew) { // updating existing instance $statusMsg = ts('"%1" report has been updated.', array(1 => $instance->title)); } elseif ($form->getVar('_id') && $isNew) { $statusMsg = ts('Your report has been successfully copied as "%1". You are currently viewing the new copy.', array(1 => $instance->title)); } else { $statusMsg = ts('"%1" report has been successfully created. You are currently viewing the new report instance.', array(1 => $instance->title)); } CRM_Core_Session::setStatus($statusMsg); if ($redirect) { $urlParams = array('reset' => 1); if ($view_mode == 'view') { $urlParams['force'] = 1; } else { $urlParams['output'] = 'criteria'; } CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/report/instance/{$instance->id}", $urlParams)); } }
/** * Post Processing function for Form. * * postProcessCommon should be used to set other variables from input as the api accesses that function. * This function is not accessed when the api calls the report. */ public function beginPostProcess() { $this->setParams($this->controller->exportValues($this->_name)); if (empty($this->_params) && $this->_force) { $this->setParams($this->_formValues); } // hack to fix params when submitted from dashboard, CRM-8532 // fields array is missing because form building etc is skipped // in dashboard mode for report //@todo - this could be done in the dashboard no we have a setter if (empty($this->_params['fields']) && !$this->_noFields) { $this->setParams($this->_formValues); } $this->processReportMode(); if ($this->_outputMode == 'save' || $this->_outputMode == 'copy') { $this->_createNew = $this->_outputMode == 'copy'; CRM_Report_Form_Instance::postProcess($this); } if ($this->_outputMode == 'delete') { CRM_Report_BAO_ReportInstance::doFormDelete($this->_id, 'civicrm/report/list?reset=1', 'civicrm/report/list?reset=1'); } $this->_formValues = $this->_params; $this->beginPostProcessCommon(); }
/** * Delete the survey. * * @param int $id * Survey id. * * @return mixed|null */ public static function del($id) { if (!$id) { return NULL; } $reportId = CRM_Campaign_BAO_Survey::getReportID($id); if ($reportId) { CRM_Report_BAO_ReportInstance::del($reportId); } $dao = new CRM_Campaign_DAO_Survey(); $dao->id = $id; return $dao->delete(); }
/** * Delete a report instance wrapped in handling for the form layer. * * @param int $instanceId * @param string $bounceTo * Url to redirect the browser to on fail. * @param string $successRedirect */ public static function doFormDelete($instanceId, $bounceTo = 'civicrm/report/list?reset=1', $successRedirect = NULL) { if (!CRM_Core_Permission::check('administer Reports')) { $statusMessage = ts('You do not have permission to Delete Report.'); CRM_Core_Error::statusBounce($statusMessage, $bounceTo); } CRM_Report_BAO_ReportInstance::del($instanceId); CRM_Core_Session::setStatus(ts('Selected report has been deleted.'), ts('Deleted'), 'success'); if ($successRedirect) { CRM_Utils_System::redirect(CRM_Utils_System::url($successRedirect)); } }