diff --git a/application/dashboard.class.inc.php b/application/dashboard.class.inc.php index e03a845a4..b7b76ba71 100644 --- a/application/dashboard.class.inc.php +++ b/application/dashboard.class.inc.php @@ -893,11 +893,53 @@ class RuntimeDashboard extends Dashboard $oDashboard->FromXml($sDashboardDefinition); $oDashboard->SetCustomFlag($bCustomized); $oDashboard->SetDefinitionFile($sDashboardFile); - } - else - { + } else { $oDashboard = null; } + + return $oDashboard; + } + + /** + * @param string $sDashboardFile file name relative to the current module folder + * @param string $sDashBoardId code of the dashboard either menu_id or __ + * + * @return null|RuntimeDashboard + * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \MissingQueryArgument + * @throws \MySQLException + * @throws \MySQLHasGoneAwayException + * @throws \Exception + */ + public static function GetDashboardToEdit($sDashboardFile, $sDashBoardId) + { + $bCustomized = false; + + // Search for an eventual user defined dashboard + $oUDSearch = new DBObjectSearch('UserDashboard'); + $oUDSearch->AddCondition('user_id', UserRights::GetUserId(), '='); + $oUDSearch->AddCondition('menu_code', $sDashBoardId, '='); + $oUDSet = new DBObjectSet($oUDSearch); + if ($oUDSet->Count() > 0) { + // Assuming there is at most one couple {user, menu}! + $oUserDashboard = $oUDSet->Fetch(); + $sDashboardDefinition = $oUserDashboard->Get('contents'); + $bCustomized = true; + } else { + $sDashboardDefinition = @file_get_contents($sDashboardFile); + } + + + if ($sDashboardDefinition !== false) { + $oDashboard = new RuntimeDashboard($sDashBoardId); + $oDashboard->FromXml($sDashboardDefinition); + $oDashboard->SetCustomFlag($bCustomized); + $oDashboard->SetDefinitionFile($sDashboardFile); + } else { + $oDashboard = null; + } + return $oDashboard; } @@ -907,8 +949,7 @@ class RuntimeDashboard extends Dashboard */ public function Render($oPage, $bEditMode = false, $aExtraParams = array(), $bCanEdit = true) { - if (!isset($aExtraParams['query_params']) && isset($aExtraParams['this->class'])) - { + if (!isset($aExtraParams['query_params']) && isset($aExtraParams['this->class'])) { $oObj = MetaModel::GetObject($aExtraParams['this->class'], $aExtraParams['this->id']); $aRenderParams = array('query_params' => $oObj->ToArgsForQuery()); } diff --git a/pages/ajax.render.php b/pages/ajax.render.php index b8c8d2874..b85fe3445 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -1030,6 +1030,7 @@ try $sDashboardId = utils::ReadParam('dashboard_id', '', false, 'raw_data'); $aExtraParams = utils::ReadParam('extra_params', array(), false, 'raw_data'); $sReloadURL = utils::ReadParam('reload_url', '', false, 'raw_data'); + appUserPreferences::SetPref('display_original_dashboard_'.$sDashboardId, false); $sJSExtraParams = json_encode($aExtraParams); $aParams = array(); $aParams['layout_class'] = utils::ReadParam('layout_class', ''); @@ -1105,11 +1106,9 @@ EOF $sDashboardFile = utils::ReadParam('file', '', false, 'raw_data'); $sReloadURL = utils::ReadParam('reload_url', '', false, 'raw_data'); $oKPI = new ExecutionKPI(); - $oDashboard = RuntimeDashboard::GetDashboard($sDashboardFile, $sId); - if (!is_null($oDashboard)) - { - if (!empty($sReloadURL)) - { + $oDashboard = RuntimeDashboard::GetDashboardToEdit($sDashboardFile, $sId); + if (!is_null($oDashboard)) { + if (!empty($sReloadURL)) { $oDashboard->SetReloadURL($sReloadURL); } $oDashboard->RenderEditor($oPage, $aExtraParams);