Exemplo n.º 1
0
 /**
  * run this page (figure out the action needed and perform it).
  *
  * @return void
  */
 function run()
 {
     if (!CRM_Core_Permission::check('administer Reports')) {
         return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/report/list', 'reset=1'));
     }
     $optionVal = CRM_Report_Utils_Report::getValueFromUrl();
     $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value', 'String', FALSE);
     $extKey = strpos(CRM_Utils_Array::value('name', $templateInfo), '.');
     $reportClass = NULL;
     if ($extKey !== FALSE) {
         $ext = CRM_Extension_System::singleton()->getMapper();
         $reportClass = $ext->keyToClass($templateInfo['name'], 'report');
         $templateInfo['name'] = $reportClass;
     }
     if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form') || !is_null($reportClass)) {
         CRM_Utils_System::setTitle($templateInfo['label'] . ' - Template');
         $this->assign('reportTitle', $templateInfo['label']);
         $session = CRM_Core_Session::singleton();
         $session->set('reportDescription', $templateInfo['description']);
         $wrapper = new CRM_Utils_Wrapper();
         return $wrapper->run($templateInfo['name'], NULL, NULL);
     }
     if ($optionVal) {
         CRM_Core_Session::setStatus(ts('Could not find the report template. Make sure the report template is registered and / or url is correct.'), ts('Template Not Found'), 'error');
     }
     return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/report/list', 'reset=1'));
 }
Exemplo n.º 2
0
 /**
  * run this page (figure out the action needed and perform it).
  *
  * @return void
  */
 function run()
 {
     $instanceId = CRM_Report_Utils_Report::getInstanceID();
     $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('Your do not have permission to Delete Report.');
             CRM_Core_Error::statusBounce($statusMessage, $reportUrl);
         }
         CRM_Report_BAO_Instance::delete($instanceId);
         CRM_Core_Session::setStatus(ts('Selected Instance has been deleted.'));
     } else {
         require_once 'CRM/Core/OptionGroup.php';
         $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value');
         if (strstr($templateInfo['name'], '_Form')) {
             $instanceInfo = array();
             CRM_Report_BAO_Instance::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.'));
     }
     return CRM_Utils_System::redirect($reportUrl);
 }
Exemplo n.º 3
0
 /**
  * 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);
 }
Exemplo n.º 4
0
 /**
  * run this page (figure out the action needed and perform it).
  *
  * @return void
  */
 function run()
 {
     $instanceId = CRM_Report_Utils_Report::getInstanceID();
     if (!$instanceId) {
         $instanceId = CRM_Report_Utils_Report::getInstanceIDForPath();
     }
     $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('Your do not have permission to Delete Report.');
             CRM_Core_Error::statusBounce($statusMessage, $reportUrl);
         }
         $navId = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_Instance', $instanceId, 'navigation_id', 'id');
         CRM_Report_BAO_Instance::delete($instanceId);
         //delete navigation if exists
         if ($navId) {
             require_once 'CRM/Core/BAO/Navigation.php';
             CRM_Core_BAO_Navigation::processDelete($navId);
             CRM_Core_BAO_Navigation::resetNavigation();
         }
         CRM_Core_Session::setStatus(ts('Selected Instance has been deleted.'));
     } else {
         require_once 'CRM/Core/OptionGroup.php';
         $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value');
         $extKey = strpos($templateInfo['name'], '.');
         $reportClass = null;
         if ($extKey !== FALSE) {
             require_once 'CRM/Core/Extensions.php';
             $ext = new CRM_Core_Extensions();
             $reportClass = $ext->keyToClass($templateInfo['name'], 'report');
             $templateInfo['name'] = $reportClass;
         }
         if (strstr($templateInfo['name'], '_Form') || !is_null($reportClass)) {
             $instanceInfo = array();
             CRM_Report_BAO_Instance::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.'));
     }
     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);
    }
}
Exemplo n.º 6
0
 /**
  * run this page (figure out the action needed and perform it).
  *
  * @return void
  */
 function run()
 {
     if (!CRM_Core_Permission::check('administer Reports')) {
         return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/report/list', "reset=1"));
     }
     $optionVal = CRM_Report_Utils_Report::getValueFromUrl();
     require_once 'CRM/Core/OptionGroup.php';
     $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value', 'String', false);
     if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form')) {
         CRM_Utils_System::setTitle($templateInfo['label'] . ' - Template');
         $this->assign('reportTitle', $templateInfo['label']);
         $session =& CRM_Core_Session::singleton();
         $session->set('reportDescription', $templateInfo['description']);
         $wrapper =& new CRM_Utils_Wrapper();
         return $wrapper->run($templateInfo['name'], null, null);
     }
     if ($optionVal) {
         CRM_Core_Session::setStatus(ts('Could not find the report template. Make sure the report template is registered and / or url is correct.'));
     }
     return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/report/list', "reset=1"));
 }
Exemplo n.º 7
0
 function processReport()
 {
     $sendmail = CRM_Utils_Request::retrieve('sendmail', 'Boolean', CRM_Core_DAO::$_nullObject, true, null, 'REQUEST');
     $instanceId = CRM_Utils_Request::retrieve('instanceId', 'Positive', CRM_Core_DAO::$_nullObject, true, null, 'REQUEST');
     $resetVal = CRM_Utils_Request::retrieve('reset', 'Positive', CRM_Core_DAO::$_nullObject, true, null, 'REQUEST');
     $optionVal = CRM_Report_Utils_Report::getValueFromUrl($instanceId);
     echo "Report Mail Triggered...<br />";
     require_once 'CRM/Core/OptionGroup.php';
     $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', $optionVal, 'value');
     $obj = new CRM_Report_Page_Instance();
     if (strstr($templateInfo['name'], '_Form')) {
         $instanceInfo = array();
         CRM_Report_BAO_Instance::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['urlToSession'] = array(array('urlVar' => 'instanceId', 'type' => 'Positive', 'sessionVar' => 'instanceId', 'default' => 'null'));
         return $wrapper->run($templateInfo['name'], null, $arguments);
     }
 }
Exemplo n.º 8
0
 /**
  * Takes an associative array and creates an instance object.
  *
  * the function extract all the params it needs to initialize the create a
  * instance object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  *
  * @return CRM_Report_DAO_ReportInstance
  */
 public static function add(&$params)
 {
     $instance = new CRM_Report_DAO_ReportInstance();
     if (empty($params)) {
         return NULL;
     }
     $instanceID = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('instance_id', $params));
     // convert roles array to string
     if (isset($params['grouprole']) && is_array($params['grouprole'])) {
         $grouprole_array = array();
         foreach ($params['grouprole'] as $key => $value) {
             $grouprole_array[$value] = $value;
         }
         $params['grouprole'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($grouprole_array));
     }
     if (!$instanceID || !isset($params['id'])) {
         $params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, FALSE);
         $params['domain_id'] = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID());
         // CRM-17256 set created_id on report creation.
         $params['created_id'] = isset($params['created_id']) ? $params['created_id'] : CRM_Core_Session::getLoggedInContactID();
     }
     if ($instanceID) {
         CRM_Utils_Hook::pre('edit', 'ReportInstance', $instanceID, $params);
     } else {
         CRM_Utils_Hook::pre('create', 'ReportInstance', NULL, $params);
     }
     $instance = new CRM_Report_DAO_ReportInstance();
     $instance->copyValues($params);
     if (CRM_Core_Config::singleton()->userFramework == 'Joomla') {
         $instance->permission = 'null';
     }
     // explicitly set to null if params value is empty
     if (!$instanceID && empty($params['grouprole'])) {
         $instance->grouprole = 'null';
     }
     if ($instanceID) {
         $instance->id = $instanceID;
     }
     if (!$instanceID) {
         if ($reportID = CRM_Utils_Array::value('report_id', $params)) {
             $instance->report_id = $reportID;
         } elseif ($instanceID) {
             $instance->report_id = CRM_Report_Utils_Report::getValueFromUrl($instanceID);
         } else {
             // just take it from current url
             $instance->report_id = CRM_Report_Utils_Report::getValueFromUrl();
         }
     }
     $instance->save();
     if ($instanceID) {
         CRM_Utils_Hook::pre('edit', 'ReportInstance', $instance->id, $instance);
     } else {
         CRM_Utils_Hook::pre('create', 'ReportInstance', $instance->id, $instance);
     }
     return $instance;
 }
Exemplo n.º 9
0
 /**
  * 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));
     }
 }
Exemplo n.º 10
0
 static function postProcess(&$form)
 {
     $params = $form->getVar('_params');
     $config = CRM_Core_Config::singleton();
     $params['header'] = $params['report_header'];
     $params['footer'] = $params['report_footer'];
     $params['domain_id'] = CRM_Core_Config::domainID();
     $form->_navigation['permission'] = array();
     $form->_navigation['label'] = $params['title'];
     $form->_navigation['name'] = $params['title'];
     //navigation parameters
     if (CRM_Utils_Array::value('is_navigation', $params)) {
         $permission = CRM_Utils_Array::value('permission', $params);
         $form->_navigation['current_parent_id'] = CRM_Utils_Array::value('parent_id', $form->_navigation);
         $form->_navigation['parent_id'] = CRM_Utils_Array::value('parent_id', $params);
         $form->_navigation['is_active'] = 1;
         if ($permission) {
             $form->_navigation['permission'][] = $permission;
         }
         //unset the navigation related element,
         //not used in report form values
         unset($params['parent_id']);
         unset($params['is_navigation']);
     }
     // convert roles array to string
     if (isset($params['grouprole']) && is_array($params['grouprole'])) {
         $grouprole_array = array();
         foreach ($params['grouprole'] as $key => $value) {
             $grouprole_array[$value] = $value;
         }
         $params['grouprole'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($grouprole_array));
     }
     // add to dashboard
     $dashletParams = array();
     if (CRM_Utils_Array::value('addToDashboard', $params)) {
         $dashletParams = array('label' => $params['title'], 'is_active' => 1);
         $permission = CRM_Utils_Array::value('permission', $params);
         if ($permission) {
             $dashletParams['permission'][] = $permission;
         }
     }
     $params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, FALSE);
     $dao = new CRM_Report_DAO_Instance();
     $dao->copyValues($params);
     if ($config->userFramework == 'Joomla') {
         $dao->permission = 'null';
     }
     // explicitly set to null if params value is empty
     if (empty($params['grouprole'])) {
         $dao->grouprole = 'null';
     }
     // unset all the params that we use
     $fields = array('title', 'to_emails', 'cc_emails', 'header', 'footer', 'qfKey', '_qf_default', 'report_header', 'report_footer', 'grouprole');
     foreach ($fields as $field) {
         unset($params[$field]);
     }
     $dao->form_values = serialize($params);
     $instanceID = $form->getVar('_id');
     $isNew = $form->getVar('_createNew');
     if ($instanceID && !$isNew) {
         $dao->id = $instanceID;
     }
     $dao->report_id = CRM_Report_Utils_Report::getValueFromUrl($instanceID);
     $dao->save();
     $form->set('id', $dao->id);
     $reloadTemplate = FALSE;
     if ($dao->id) {
         if (!empty($form->_navigation)) {
             if ($isNew && CRM_Utils_Array::value('id', $form->_navigation)) {
                 unset($form->_navigation['id']);
             }
             $form->_navigation['url'] = "civicrm/report/instance/{$dao->id}&reset=1";
             $navigation = CRM_Core_BAO_Navigation::add($form->_navigation);
             if (CRM_Utils_Array::value('is_active', $form->_navigation)) {
                 //set the navigation id in report instance table
                 CRM_Core_DAO::setFieldValue('CRM_Report_DAO_Instance', $dao->id, 'navigation_id', $navigation->id);
             } else {
                 // has been removed from the navigation bar
                 CRM_Core_DAO::setFieldValue('CRM_Report_DAO_Instance', $dao->id, 'navigation_id', 'NULL');
             }
             //reset navigation
             CRM_Core_BAO_Navigation::resetNavigation();
             // in order to reflect change in navigation, template needs to be reloaded
             $reloadTemplate = TRUE;
         }
         // add to dashlet
         if (!empty($dashletParams)) {
             $section = 2;
             $chart = '';
             if (CRM_Utils_Array::value('charts', $params)) {
                 $section = 1;
                 $chart = "&charts=" . $params['charts'];
             }
             $dashletParams['url'] = "civicrm/report/instance/{$dao->id}&reset=1&section={$section}&snippet=5{$chart}&context=dashlet";
             $dashletParams['fullscreen_url'] = "civicrm/report/instance/{$dao->id}&reset=1&section={$section}&snippet=5{$chart}&context=dashletFullscreen";
             $dashletParams['instanceURL'] = "civicrm/report/instance/{$dao->id}";
             CRM_Core_BAO_Dashboard::addDashlet($dashletParams);
         }
         $instanceParams = array('value' => $dao->report_id);
         $instanceDefaults = array();
         $cmpName = "Contact";
         $statusMsg = "null";
         CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_OptionValue', $instanceParams, $instanceDefaults);
         if ($cmpID = CRM_Utils_Array::value('component_id', $instanceDefaults)) {
             $cmpName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Component', $cmpID, 'name', 'id');
             $cmpName = substr($cmpName, 4);
         }
         // Url to view this report and others created FROM this template
         $instanceUrl = CRM_Utils_System::url('civicrm/report/list', "reset=1&ovid={$instanceDefaults['id']}");
         $statusMsg = ts('Report "%1" has been created and is now available in the <a href="%3">report listings under "%2" Reports</a>.', array(1 => $dao->title, 2 => $cmpName, 3 => $instanceUrl));
         if ($instanceID && !$isNew) {
             $statusMsg = ts('Report "%1" has been updated.', array(1 => $dao->title));
         }
         CRM_Core_Session::setStatus($statusMsg);
     }
     if ($reloadTemplate) {
         // as there's been change in navigation, reload the template
         return CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'force=1'));
     }
 }
Exemplo n.º 11
0
 static function postProcess(&$form)
 {
     $params = $form->getVar('_params');
     $config = CRM_Core_Config::singleton();
     $params['header'] = $params['report_header'];
     $params['footer'] = $params['report_footer'];
     $params['domain_id'] = CRM_Core_Config::domainID();
     //navigation parameters
     if (CRM_Utils_Array::value('is_navigation', $params)) {
         $form->_navigation['permission'] = array();
         $permission = CRM_Utils_Array::value('permission', $params);
         $form->_navigation['current_parent_id'] = CRM_Utils_Array::value('parent_id', $form->_navigation);
         $form->_navigation['parent_id'] = CRM_Utils_Array::value('parent_id', $params);
         $form->_navigation['label'] = $params['title'];
         $form->_navigation['name'] = $params['title'];
         $form->_navigation['is_active'] = 1;
         if ($permission) {
             $form->_navigation['permission'][] = $permission;
         }
         //unset the navigation related element,
         //not used in report form values
         unset($params['parent_id']);
         unset($params['is_navigation']);
     }
     // add to dashboard
     $dashletParams = array();
     if (CRM_Utils_Array::value('addToDashboard', $params)) {
         $dashletParams = array('label' => $params['title'], 'is_active' => 1, 'content' => 'NULL');
         $permission = CRM_Utils_Array::value('permission', $params);
         if ($permission) {
             $dashletParams['permission'][] = $permission;
         }
         unset($params['addToDashboard']);
     }
     require_once 'CRM/Report/DAO/Instance.php';
     $dao = new CRM_Report_DAO_Instance();
     $dao->copyValues($params);
     if ($config->userFramework == 'Joomla') {
         $dao->permission = NULL;
     }
     // unset all the params that we use
     $fields = array('title', 'to_emails', 'cc_emails', 'header', 'footer', 'qfKey', '_qf_default', 'report_header', 'report_footer');
     foreach ($fields as $field) {
         unset($params[$field]);
     }
     $dao->form_values = serialize($params);
     $instanceID = $form->getVar('_id');
     if ($instanceID) {
         $dao->id = $instanceID;
     }
     require_once 'CRM/Report/Utils/Report.php';
     $dao->report_id = CRM_Report_Utils_Report::getValueFromUrl($instanceID);
     $dao->save();
     $form->set('id', $dao->id);
     $reloadTemplate = false;
     if ($dao->id) {
         if (!empty($form->_navigation)) {
             $form->_navigation['url'] = "civicrm/report/instance/{$dao->id}&reset=1";
             $navigation = CRM_Core_BAO_Navigation::add($form->_navigation);
             //set the navigation id in report instance table
             CRM_Core_DAO::setFieldValue('CRM_Report_DAO_Instance', $dao->id, 'navigation_id', $navigation->id);
             //reset navigation
             CRM_Core_BAO_Navigation::resetNavigation();
             // in order to reflect change in navigation, template needs to be reloaded
             $reloadTemplate = true;
         }
         // add to dashlet
         if (!empty($dashletParams)) {
             $section = 2;
             $chart = '';
             if (CRM_Utils_Array::value('charts', $params)) {
                 $section = 1;
                 $chart = "&charts=" . $params['charts'];
                 $dashletParams['is_fullscreen'] = 0;
             }
             $dashletParams['url'] = "civicrm/report/instance/{$dao->id}&reset=1&section={$section}&snippet=4{$chart}";
             $dashletParams['instanceURL'] = "civicrm/report/instance/{$dao->id}";
             require_once 'CRM/Core/BAO/Dashboard.php';
             CRM_Core_BAO_Dashboard::addDashlet($dashletParams);
         }
         $instanceParams = array('value' => $dao->report_id);
         $instanceDefaults = array();
         $cmpName = "Contact";
         $statusMsg = "null";
         CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_OptionValue', $instanceParams, $instanceDefaults);
         if ($cmpID = CRM_Utils_Array::value('component_id', $instanceDefaults)) {
             $cmpName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Component', $cmpID, 'name', 'id');
             $cmpName = substr($cmpName, 4);
         }
         // Url to view this report and others created FROM this template
         $instanceUrl = CRM_Utils_System::url('civicrm/report/list', "reset=1&ovid={$instanceDefaults['id']}");
         $statusMsg = ts('Report "%1" has been created and is now available in the <a href="%3">report listings under "%2" Reports</a>.', array(1 => $dao->title, 2 => $cmpName, 3 => $instanceUrl));
         if ($instanceID) {
             $statusMsg = ts('Report "%1" has been updated.', array(1 => $dao->title));
         }
         CRM_Core_Session::setStatus($statusMsg);
     }
     if ($reloadTemplate) {
         // as there's been change in navigation, reload the template
         return CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'force=1'));
     }
 }