/** * Run dashboard. * * @return void */ public function run() { // Add dashboard js and css $resources = CRM_Core_Resources::singleton(); $resources->addScriptFile('civicrm', 'js/jquery/jquery.dashboard.js', 0, 'html-header', FALSE); $resources->addStyleFile('civicrm', 'css/dashboard.css'); $resetCache = CRM_Utils_Request::retrieve('resetCache', 'Positive', CRM_Core_DAO::$_nullObject); CRM_Utils_System::setTitle(ts('CiviCRM Home')); $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); if ($resetCache) { CRM_Core_BAO_Dashboard::resetDashletCache($contactID); } // call hook to get html from other modules // ignored but needed to prevent warnings $contentPlacement = CRM_Utils_Hook::DASHBOARD_BELOW; $html = CRM_Utils_Hook::dashboard($contactID, $contentPlacement); if (is_array($html)) { $this->assign_by_ref('hookContent', $html); $this->assign('hookContentPlacement', $contentPlacement); } $communityMessages = CRM_Core_CommunityMessages::create(); if ($communityMessages->isEnabled()) { $message = $communityMessages->pick(); if ($message) { $this->assign('communityMessages', $communityMessages->evalMarkup($message['markup'])); } } return parent::run(); }
/** * Run dashboard * * @return void * @access public */ function run() { CRM_Utils_System::setTitle(ts('Dashlets')); $this->assign('admin', CRM_Core_Permission::check('administer CiviCRM')); // get all dashlets $allDashlets = CRM_Core_BAO_Dashboard::getDashlets(FALSE); // get dashlets for logged in contact $currentDashlets = CRM_Core_BAO_Dashboard::getContactDashlets(); $contactDashlets = $availableDashlets = array(); foreach ($currentDashlets as $columnNo => $values) { foreach ($values as $val => $isMinimized) { list($weight, $dashletID) = explode('-', $val); $key = "{$dashletID}-{$isMinimized}"; $contactDashlets[$columnNo][$key] = array('label' => $allDashlets[$dashletID]['label'], 'is_reserved' => $allDashlets[$dashletID]['is_reserved']); unset($allDashlets[$dashletID]); } } foreach ($allDashlets as $dashletID => $values) { $key = "{$dashletID}-0"; $availableDashlets[$key] = array('label' => $values['label'], 'is_reserved' => $values['is_reserved']); } $this->assign('contactDashlets', $contactDashlets); $this->assign('availableDashlets', $availableDashlets); return parent::run(); }
/** * Delete a specified Dashlet. * * @param array $params * Array holding 'id' of dashlet to be deleted. * * @return array */ function civicrm_api3_dashboard_delete($params) { if (CRM_Core_BAO_Dashboard::deleteDashlet($params['id'])) { return civicrm_api3_create_success(1, $params, 'Dashboard', 'delete'); } else { return civicrm_api3_create_error('Could not delete dashlet'); } }
function _civicrm_api3_dashboard_contact_check_params(&$params) { $dashboard_id = CRM_Utils_Array::value('dashboard_id', $params); if ($dashboard_id) { $allDashlets = CRM_Core_BAO_Dashboard::getDashlets(TRUE, CRM_Utils_Array::value('check_permissions', $params, 0)); if (!isset($allDashlets[$dashboard_id])) { return civicrm_api3_create_error('Invalid or inaccessible dashboard ID'); } } return NULL; }
/** * Run dashboard * * @return none * @access public */ function run() { $resetCache = CRM_Utils_Request::retrieve('resetCache', 'Positive', CRM_Core_DAO::$_nullObject); if ($resetCache) { CRM_Core_BAO_Dashboard::resetDashletCache(); } CRM_Utils_System::setTitle(ts('CiviCRM Home')); $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); // call hook to get html from other modules // ignored but needed to prevent warnings $contentPlacement = CRM_Utils_Hook::DASHBOARD_BELOW; $html = CRM_Utils_Hook::dashboard($contactID, $contentPlacement); if (is_array($html)) { $this->assign_by_ref('hookContent', $html); $this->assign('hookContentPlacement', $contentPlacement); } //check that default FROM email address, owner (domain) organization name and default mailbox are configured. $fromEmailOK = TRUE; $ownerOrgOK = TRUE; $defaultMailboxOK = TRUE; // Don't put up notices if user doesn't have administer CiviCRM permission if (CRM_Core_Permission::check('administer CiviCRM')) { $destination = CRM_Utils_System::url('civicrm/dashboard', 'reset=1', FALSE, NULL, FALSE); $destination = urlencode($destination); list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE); if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') { $fixEmailUrl = CRM_Utils_System::url("civicrm/admin/domain", "action=update&reset=1&civicrmDestination={$destination}"); $this->assign('fixEmailUrl', $fixEmailUrl); $fromEmailOK = FALSE; } $domain = CRM_Core_BAO_Domain::getDomain(); $domainName = $domain->name; if (!$domainName || $domainName == 'Default Domain Name') { $fixOrgUrl = CRM_Utils_System::url("civicrm/admin/domain", "action=update&reset=1&civicrmDestination={$destination}"); $this->assign('fixOrgUrl', $fixOrgUrl); $ownerOrgOK = FALSE; } $config = CRM_Core_Config::singleton(); if (in_array('CiviMail', $config->enableComponents) && CRM_Core_BAO_MailSettings::defaultDomain() == "FIXME.ORG") { $fixDefaultMailbox = CRM_Utils_System::url('civicrm/admin/mailSettings', "reset=1&civicrmDestination={$destination}"); $this->assign('fixDefaultMailbox', $fixDefaultMailbox); $defaultMailboxOK = FALSE; } } $this->assign('fromEmailOK', $fromEmailOK); $this->assign('ownerOrgOK', $ownerOrgOK); $this->assign('defaultMailboxOK', $defaultMailboxOK); return parent::run(); }
/** * Run dashboard * * @return none * @access public */ function run() { $resetCache = CRM_Utils_Request::retrieve('resetCache', 'Positive', CRM_Core_DAO::$_nullObject); if ($resetCache) { require_once 'CRM/Core/BAO/Dashboard.php'; CRM_Core_BAO_Dashboard::resetDashletCache(); } CRM_Utils_System::setTitle(ts('CiviCRM Home')); $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); // call hook to get html from other modules require_once 'CRM/Utils/Hook.php'; $contentPlacement = CRM_Utils_Hook::DASHBOARD_BELOW; // ignored but needed to prevent warnings $html = CRM_Utils_Hook::dashboard($contactID, $contentPlacement); if (is_array($html)) { $this->assign_by_ref('hookContent', $html); $this->assign('hookContentPlacement', $contentPlacement); } return parent::run(); }
/** * Run dashboard. */ public function run() { CRM_Utils_System::setTitle(ts('Dashlets')); $this->assign('admin', CRM_Core_Permission::check('administer CiviCRM')); // get all dashlets $allDashlets = CRM_Core_BAO_Dashboard::getDashlets(FALSE); // get dashlets for logged in contact $currentDashlets = CRM_Core_BAO_Dashboard::getContactDashlets(); $contactDashlets = $availableDashlets = array(); foreach ($currentDashlets as $item) { $key = "{$item['dashboard_id']}-0"; $contactDashlets[$item['column_no']][$key] = array('label' => $item['label'], 'is_reserved' => $allDashlets[$item['dashboard_id']]['is_reserved']); unset($allDashlets[$item['dashboard_id']]); } foreach ($allDashlets as $dashletID => $values) { $key = "{$dashletID}-0"; $availableDashlets[$key] = array('label' => $values['label'], 'is_reserved' => $values['is_reserved']); } $this->assign('contactDashlets', $contactDashlets); $this->assign('availableDashlets', $availableDashlets); return parent::run(); }
/** * Function used for CiviCRM dashboard operations. */ public static function dashboard() { $operation = CRM_Utils_Type::escape($_REQUEST['op'], 'String'); switch ($operation) { case 'get_widgets_by_column': // This would normally be coming from either the database (this user's settings) or a default/initial dashboard configuration. // get contact id of logged in user $dashlets = CRM_Core_BAO_Dashboard::getContactDashlets(); break; case 'get_widget': $dashletID = CRM_Utils_Type::escape($_GET['id'], 'Positive'); $dashlets = CRM_Core_BAO_Dashboard::getDashletInfo($dashletID); break; case 'save_columns': CRM_Core_BAO_Dashboard::saveDashletChanges($_REQUEST['columns']); CRM_Utils_System::civiExit(); case 'delete_dashlet': $dashletID = CRM_Utils_Type::escape($_REQUEST['dashlet_id'], 'Positive'); CRM_Core_BAO_Dashboard::deleteDashlet($dashletID); CRM_Utils_System::civiExit(); } CRM_Utils_JSON::output($dashlets); }
/** * Create instance. * takes an associative array and creates a instance object and does any related work like permissioning, adding to dashboard etc. * * This function is invoked from within the web form layer and also from the api layer * * @param array $params * (reference ) an assoc array of name/value pairs. * * @return CRM_Report_BAO_ReportInstance */ public static function &create(&$params) { if (isset($params['report_header'])) { $params['header'] = CRM_Utils_Array::value('report_header', $params); } if (isset($params['report_footer'])) { $params['footer'] = CRM_Utils_Array::value('report_footer', $params); } // build navigation parameters if (!empty($params['is_navigation'])) { if (!array_key_exists('navigation', $params)) { $params['navigation'] = array(); } $navigationParams =& $params['navigation']; $navigationParams['permission'] = array(); $navigationParams['label'] = $params['title']; $navigationParams['name'] = $params['title']; $navigationParams['current_parent_id'] = CRM_Utils_Array::value('parent_id', $navigationParams); $navigationParams['parent_id'] = CRM_Utils_Array::value('parent_id', $params); $navigationParams['is_active'] = 1; if ($permission = CRM_Utils_Array::value('permission', $params)) { $navigationParams['permission'][] = $permission; } // unset the navigation related elements, not used in report form values unset($params['parent_id']); unset($params['is_navigation']); } // add to dashboard $dashletParams = array(); if (!empty($params['addToDashboard'])) { $dashletParams = array('label' => $params['title'], 'is_active' => 1); if ($permission = CRM_Utils_Array::value('permission', $params)) { $dashletParams['permission'][] = $permission; } } $transaction = new CRM_Core_Transaction(); $instance = self::add($params); if (is_a($instance, 'CRM_Core_Error')) { $transaction->rollback(); return $instance; } // add / update navigation as required if (!empty($navigationParams)) { if (empty($params['id']) && empty($params['instance_id']) && !empty($navigationParams['id'])) { unset($navigationParams['id']); } $navigationParams['url'] = "civicrm/report/instance/{$instance->id}?reset=1"; $navigation = CRM_Core_BAO_Navigation::add($navigationParams); if (!empty($navigationParams['is_active'])) { //set the navigation id in report instance table CRM_Core_DAO::setFieldValue('CRM_Report_DAO_ReportInstance', $instance->id, 'navigation_id', $navigation->id); } else { // has been removed from the navigation bar CRM_Core_DAO::setFieldValue('CRM_Report_DAO_ReportInstance', $instance->id, 'navigation_id', 'NULL'); } //reset navigation CRM_Core_BAO_Navigation::resetNavigation(); } // add to dashlet if (!empty($dashletParams)) { $section = 2; $chart = ''; if (!empty($params['charts'])) { $section = 1; $chart = "&charts=" . $params['charts']; } $limitResult = NULL; if (!empty($params['row_count'])) { $limitResult = '&rowCount=' . $params['row_count']; } $dashletParams['name'] = "report/{$instance->id}"; $dashletParams['url'] = "civicrm/report/instance/{$instance->id}?reset=1§ion={$section}&snippet=5{$chart}&context=dashlet" . $limitResult; $dashletParams['fullscreen_url'] = "civicrm/report/instance/{$instance->id}?reset=1§ion={$section}&snippet=5{$chart}&context=dashletFullscreen" . $limitResult; $dashletParams['instanceURL'] = "civicrm/report/instance/{$instance->id}"; CRM_Core_BAO_Dashboard::addDashlet($dashletParams); } $transaction->commit(); return $instance; }
/** * Reset navigation for all contacts * * @param integer $contactID - reset only entries belonging to that contact ID */ static function resetNavigation($contactID = NULL) { $params = array(); $query = "UPDATE civicrm_setting SET value = NULL WHERE name='navigation'"; if ($contactID) { $query .= " AND contact_id = %1"; $params[1] = array($contactID, 'Integer'); } else { $query .= " AND contact_id IS NOT NULL"; } CRM_Core_DAO::executeQuery($query, $params); CRM_Core_BAO_Cache::deleteGroup('navigation'); // also reset the dashlet cache in case permissions have changed etc CRM_Core_BAO_Dashboard::resetDashletCache($contactID); }
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§ion={$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')); } }
/** * Reset navigation for all contacts or a specified contact. * * @param int $contactID * Reset only entries belonging to that contact ID. * * @return string */ public static function resetNavigation($contactID = NULL) { $newKey = CRM_Utils_String::createRandom(self::CACHE_KEY_STRLEN, CRM_Utils_String::ALPHANUMERIC); if (!$contactID) { $query = "UPDATE civicrm_setting SET value = '{$newKey}' WHERE name='navigation' AND contact_id IS NOT NULL"; CRM_Core_DAO::executeQuery($query); CRM_Core_BAO_Cache::deleteGroup('navigation'); } else { // before inserting check if contact id exists in db // this is to handle weird case when contact id is in session but not in db $contact = new CRM_Contact_DAO_Contact(); $contact->id = $contactID; if ($contact->find(TRUE)) { CRM_Core_BAO_Setting::setItem($newKey, CRM_Core_BAO_Setting::PERSONAL_PREFERENCES_NAME, 'navigation', NULL, $contactID, $contactID); } } // also reset the dashlet cache in case permissions have changed etc // FIXME: decouple this CRM_Core_BAO_Dashboard::resetDashletCache($contactID); return $newKey; }
/** * Function used for CiviCRM dashboard operations */ static function dashboard() { $operation = CRM_Utils_Type::escape($_REQUEST['op'], 'String'); switch ($operation) { case 'get_widgets_by_column': // This would normally be coming from either the database (this user's settings) or a default/initial dashboard configuration. // get contact id of logged in user require_once 'CRM/Core/BAO/Dashboard.php'; $dashlets = CRM_Core_BAO_Dashboard::getContactDashlets(); break; case 'get_widget': $dashletID = CRM_Utils_Type::escape($_GET['id'], 'Positive'); require_once 'CRM/Core/BAO/Dashboard.php'; $dashlets = CRM_Core_BAO_Dashboard::getDashletInfo($dashletID); break; case 'save_columns': require_once 'CRM/Core/BAO/Dashboard.php'; CRM_Core_BAO_Dashboard::saveDashletChanges($_POST['columns']); exit; case 'delete_dashlet': $dashletID = CRM_Utils_Type::escape($_POST['dashlet_id'], 'Positive'); require_once 'CRM/Core/BAO/Dashboard.php'; CRM_Core_BAO_Dashboard::deleteDashlet($dashletID); exit; } echo json_encode($dashlets); exit; }
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§ion={$section}&snippet=5{$chart}&context=dashlet"; $dashletParams['fullscreen_url'] = "civicrm/report/instance/{$dao->id}&reset=1§ion={$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')); } }
/** * Function used for CiviCRM dashboard operations. */ public static function dashboard() { switch ($_REQUEST['op']) { case 'save_columns': CRM_Core_BAO_Dashboard::saveDashletChanges($_REQUEST['columns']); break; case 'delete_dashlet': $dashletID = CRM_Utils_Type::escape($_REQUEST['dashlet_id'], 'Positive'); CRM_Core_BAO_Dashboard::deleteDashlet($dashletID); } CRM_Utils_System::civiExit(); }
/** * Run dashboard * * @return void * @access public */ function run() { // Add dashboard js and css $resources = CRM_Core_Resources::singleton(); $resources->addScriptFile('civicrm', 'packages/jquery/plugins/jquery.dashboard.js', 0, 'html-header', FALSE); $resources->addStyleFile('civicrm', 'packages/jquery/css/dashboard.css'); $config = CRM_Core_Config::singleton(); // Add dashlet-specific js files // TODO: Need a much better way of managing on-the-fly js requirements. Require.js perhaps? // Checking if a specific dashlet is enabled is a pain and including the js here sucks anyway // So here's a compromise: if (in_array('CiviCase', $config->enableComponents)) { $resources->addScriptFile('civicrm', 'templates/CRM/Case/Form/ActivityChangeStatus.js'); } $resetCache = CRM_Utils_Request::retrieve('resetCache', 'Positive', CRM_Core_DAO::$_nullObject); CRM_Utils_System::setTitle(ts('CiviCRM Home')); $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); if ($resetCache) { CRM_Core_BAO_Dashboard::resetDashletCache($contactID); } // call hook to get html from other modules // ignored but needed to prevent warnings $contentPlacement = CRM_Utils_Hook::DASHBOARD_BELOW; $html = CRM_Utils_Hook::dashboard($contactID, $contentPlacement); if (is_array($html)) { $this->assign_by_ref('hookContent', $html); $this->assign('hookContentPlacement', $contentPlacement); } //check that default FROM email address, owner (domain) organization name and default mailbox are configured. $fromEmailOK = TRUE; $ownerOrgOK = TRUE; $defaultMailboxOK = TRUE; // Don't put up notices if user doesn't have administer CiviCRM permission if (CRM_Core_Permission::check('administer CiviCRM')) { $destination = CRM_Utils_System::url('civicrm/dashboard', 'reset=1', FALSE, NULL, FALSE); $destination = urlencode($destination); list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE); if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') { $fixEmailUrl = CRM_Utils_System::url("civicrm/admin/domain", "action=update&reset=1&civicrmDestination={$destination}"); $this->assign('fixEmailUrl', $fixEmailUrl); $fromEmailOK = FALSE; } $domain = CRM_Core_BAO_Domain::getDomain(); $domainName = $domain->name; if (!$domainName || $domainName == 'Default Domain Name') { $fixOrgUrl = CRM_Utils_System::url("civicrm/admin/domain", "action=update&reset=1&civicrmDestination={$destination}"); $this->assign('fixOrgUrl', $fixOrgUrl); $ownerOrgOK = FALSE; } if (in_array('CiviMail', $config->enableComponents) && CRM_Core_BAO_MailSettings::defaultDomain() == "EXAMPLE.ORG") { $fixDefaultMailbox = CRM_Utils_System::url('civicrm/admin/mailSettings', "reset=1&civicrmDestination={$destination}"); $this->assign('fixDefaultMailbox', $fixDefaultMailbox); $defaultMailboxOK = FALSE; } } $this->assign('fromEmailOK', $fromEmailOK); $this->assign('ownerOrgOK', $ownerOrgOK); $this->assign('defaultMailboxOK', $defaultMailboxOK); $communityMessages = CRM_Core_CommunityMessages::create(); if ($communityMessages->isEnabled()) { $message = $communityMessages->pick(); if ($message) { $this->assign('communityMessages', $communityMessages->evalMarkup($message['markup'])); } } return parent::run(); }
/** * Function to save changes made by use to the Dashlet * * @param array $columns associated array * * @return void * @access public * @static */ static function saveDashletChanges($columns) { $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); // $columns = array( 0 => array( 2 => 0 ), // 1 => array( 1 => 0 ) // ); //we need to get existing dashletes, so we know when to update or insert $contactDashlets = CRM_Core_BAO_Dashboard::getContactDashlets(true); $dashletIDs = array(); if (is_array($columns)) { foreach ($columns as $colNo => $dashlets) { if (!is_integer($colNo)) { continue; } $weight = 1; foreach ($dashlets as $dashletID => $isMinimized) { $isMinimized = (int) $isMinimized; if (in_array($dashletID, $contactDashlets)) { $query = " UPDATE civicrm_dashboard_contact \n SET weight = {$weight}, is_minimized = {$isMinimized}, column_no = {$colNo}, is_active = 1\n WHERE dashboard_id = {$dashletID} AND contact_id = {$contactID} "; } else { $query = " INSERT INTO civicrm_dashboard_contact \n ( weight, is_minimized, column_no, is_active, dashboard_id, contact_id )\n VALUES( {$weight}, {$isMinimized}, {$colNo}, 1, {$dashletID}, {$contactID} )"; } // fire update query for each column $dao = CRM_Core_DAO::executeQuery($query); $dashletIDs[] = $dashletID; $weight++; } } } if (!empty($dashletIDs)) { // we need to disable widget that removed $updateQuery = " UPDATE civicrm_dashboard_contact \n SET is_active = 0\n WHERE dashboard_id NOT IN ( " . implode(',', $dashletIDs) . ") AND contact_id = {$contactID}"; } else { // this means all widgets are disabled $updateQuery = " UPDATE civicrm_dashboard_contact \n SET is_active = 0\n WHERE contact_id = {$contactID}"; } CRM_Core_DAO::executeQuery($updateQuery); }
/** * @dataProvider parseUrlTestData * @param $input * @param $expectedResult */ public function testParseUrl($input, $expectedResult) { $this->assertEquals($expectedResult, CRM_Core_BAO_Dashboard::parseUrl($input)); }