/** * 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; }