*/ require '../path.inc.php'; // Note: i18n is included by the Controler class, but Ajax dos not use it... require_once 'i18n/i18n.inc.php'; if (Tools::isConnectedUser() && filter_input(INPUT_POST, 'action')) { $logger = Logger::getLogger("dashboardAjax"); $action = filter_input(INPUT_POST, 'action'); if ($action == 'getPluginConfigInfo') { $pluginClassName = Tools::getSecurePOSTStringValue('pluginClassName'); try { $reflectionMethod = new ReflectionMethod($pluginClassName, 'getDesc'); $pDesc = $reflectionMethod->invoke(NULL); $reflectionMethod2 = new ReflectionMethod($pluginClassName, 'getCfgFilemame'); $cfgFilename = $reflectionMethod2->invoke(NULL); $smartyHelper = new SmartyHelper(); $html = $smartyHelper->fetch($cfgFilename); $data = array('description' => htmlspecialchars($pDesc), 'attributesHtml' => $html, 'statusMsg' => 'SUCCESS'); // return html & description string $jsonData = json_encode($data); } catch (Exception $e) { $logger->error("addDashboardPlugin error: " . $e->getMessage()); $jsonData = json_encode(array('statusMsg' => T_('ERROR: could not get plugin configuration info'))); } echo $jsonData; } else { if ($action == 'addDashboardPlugin') { $pluginAttributesJsonStr = Tools::getSecurePOSTStringValue('pluginAttributesJsonStr'); $pluginAttributesJsonArray = json_decode(stripslashes($pluginAttributesJsonStr), true); //$logger->error("pluginAttributes = " . var_export($pluginAttributesJsonArray, true)); // convert to a Dashboard compatible format $pluginAttributes = array();
// TODO do not log exception if date = 01-01-1970 $startTimestamp = Tools::date2timestamp(Tools::getSecureGETStringValue("loadPerUser_startdate")); $endTimestamp = Tools::date2timestamp(Tools::getSecureGETStringValue("loadPerUser_enddate")); $attributesJsonStr = Tools::getSecureGETStringValue('attributesJsonStr'); $attributesArray = json_decode(stripslashes($attributesJsonStr), true); $showSidetasks = 'on' != $attributesArray[LoadPerUserIndicator::OPTION_SHOW_SIDETASKS] ? false : true; //$logger->error("showSidetasks = ".var_export($showSidetasks, true).' attr '.$attributesArray[LoadPerUserIndicator::OPTION_SHOW_SIDETASKS]); // update dataProvider $pluginDataProvider->setParam(PluginDataProviderInterface::PARAM_START_TIMESTAMP, $startTimestamp); $pluginDataProvider->setParam(PluginDataProviderInterface::PARAM_END_TIMESTAMP, $endTimestamp); $indicator = new LoadPerUserIndicator($pluginDataProvider); // override plugin settings with current attributes $indicator->setPluginSettings(array(LoadPerUserIndicator::OPTION_SHOW_SIDETASKS => $showSidetasks)); $indicator->execute(); $data = $indicator->getSmartyVariablesForAjax(); // construct the html table foreach ($data as $smartyKey => $smartyVariable) { $smartyHelper->assign($smartyKey, $smartyVariable); #$logger->debug("key $smartyKey = ".var_export($smartyVariable, true)); } $html = $smartyHelper->fetch(LoadPerUserIndicator::getSmartySubFilename()); $data['loadPerUser_htmlContent'] = $html; // return html & chart data $jsonData = json_encode($data); echo $jsonData; } else { Tools::sendNotFoundAccess(); } } else { Tools::sendUnauthorizedAccess(); }
/** * * @param PluginDataProvider $pluginDataProvider * @param SmartyHelper $smartyHelper * @param array $pluginAttributes * @param int $idx * @return array */ public static function getWidget($pluginDataProvider, $smartyHelper, $pluginAttributes, $idx) { $pluginClassName = $pluginAttributes['pluginClassName']; // Plugin may not exist... if (!class_exists($pluginClassName)) { $e = new Exception('getWidget: class ' . $pluginClassName . ' not found !'); throw $e; } $r = new ReflectionClass($pluginClassName); $indicator = $r->newInstanceArgs(array($pluginDataProvider)); // examples: isGraphOnly, dateRange(defaultRange|currentWeek|currentMonth|noDateLimit), ... $indicator->setPluginSettings($pluginAttributes); $indicator->execute(); $data = $indicator->getSmartyVariables(); foreach ($data as $smartyKey => $smartyVariable) { $smartyHelper->assign($smartyKey, $smartyVariable); } //self::$logger->error("Indic classname: ".$pluginClassName); //self::$logger->error("Indic SmartyFilename: ".$pluginClassName::getSmartyFilename()); $indicatorHtmlContent = $smartyHelper->fetch($pluginClassName::getSmartyFilename()); // update inettuts attributes from pluginAttributes $widgetTitle = array_key_exists('widgetTitle', $pluginAttributes) ? $pluginAttributes['widgetTitle'] : $pluginClassName::getName(); $color = array_key_exists('color', $pluginAttributes) ? $pluginAttributes['color'] : 'color-white'; unset($pluginAttributes['widgetTitle']); unset($pluginAttributes['color']); // set indicator result in a dashboard widget $widget = array('id' => 'w_' . $idx, 'color' => $color, 'title' => $widgetTitle, 'desc' => $pluginClassName::getDesc(), 'category' => implode(',', $pluginClassName::getCategories()), 'pClassName' => $pluginClassName, 'attributesJsonStr' => json_encode($pluginAttributes), 'jsFiles' => $pluginClassName::getJsFiles(), 'cssFiles' => $pluginClassName::getCssFiles(), 'content' => $indicatorHtmlContent); return $widget; }
$pluginDataProvider = unserialize($_SESSION[PluginDataProviderInterface::SESSION_ID . $dashboardId]); if (FALSE == $pluginDataProvider) { $logger->error("PluginDataProvider unserialize error (dashboardId = {$dashboardId}"); Tools::sendBadRequest("PluginDataProvider unserialize error"); } $smartyHelper = new SmartyHelper(); if ('getLoadPerJobIndicator2' == $action) { $startTimestamp = Tools::date2timestamp(Tools::getSecureGETStringValue("loadPerJob_startdate")); $endTimestamp = Tools::date2timestamp(Tools::getSecureGETStringValue("loadPerJob_enddate")); // update dataProvider $pluginDataProvider->setParam(PluginDataProviderInterface::PARAM_START_TIMESTAMP, $startTimestamp); $pluginDataProvider->setParam(PluginDataProviderInterface::PARAM_END_TIMESTAMP, $endTimestamp); $indicator = new LoadPerJobIndicator2($pluginDataProvider); $indicator->execute(); $data = $indicator->getSmartyVariablesForAjax(); // construct the html table foreach ($data as $smartyKey => $smartyVariable) { $smartyHelper->assign($smartyKey, $smartyVariable); #$logger->debug("key $smartyKey = ".var_export($smartyVariable, true)); } $html = $smartyHelper->fetch(LoadPerJobIndicator2::getSmartySubFilename()); $data['loadPerJob_htmlTable'] = $html; // return html & chart data $jsonData = json_encode($data); echo $jsonData; } else { Tools::sendNotFoundAccess(); } } else { Tools::sendUnauthorizedAccess(); }
$isDisplayTasks = $attributesArray['isDisplayTasks']; // update dataProvider $pluginDataProvider->setParam(PluginDataProviderInterface::PARAM_START_TIMESTAMP, $startTimestamp); $pluginDataProvider->setParam(PluginDataProviderInterface::PARAM_END_TIMESTAMP, $endTimestamp); $pluginDataProvider->setParam(PluginDataProviderInterface::PARAM_PROJECT_ID, $selectedProject); $indicator = new LoadPerProjCategoryIndicator($pluginDataProvider); // override plugin settings with current attributes $indicator->setPluginSettings(array(LoadPerProjCategoryIndicator::OPTION_DISPLAY_TASKS => $isDisplayTasks)); $indicator->execute(); $data = $indicator->getSmartyVariablesForAjax(); // construct the html table foreach ($data as $smartyKey => $smartyVariable) { $smartyHelper->assign($smartyKey, $smartyVariable); #$logger->debug("key $smartyKey = ".var_export($smartyVariable, true)); } $html = $smartyHelper->fetch(LoadPerProjCategoryIndicator::getSmartySubFilename()); $data['loadPerProjCategory_htmlContent'] = $html; // return html & chart data $jsonData = json_encode($data); echo $jsonData; } else { Tools::sendBadRequest("PluginDataProvider unserialize error"); } } else { Tools::sendBadRequest("PluginDataProvider not set"); } } else { Tools::sendNotFoundAccess(); } } } else {
Tools::sendBadRequest("PluginDataProvider not set"); } $pluginDataProvider = unserialize($_SESSION[PluginDataProviderInterface::SESSION_ID . $dashboardId]); if (FALSE == $pluginDataProvider) { $logger->error("PluginDataProvider unserialize error (dashboardId = {$dashboardId}"); Tools::sendBadRequest("PluginDataProvider unserialize error"); } $smartyHelper = new SmartyHelper(); if ('getHelloWorldIndicator' == $action) { $startTimestamp = Tools::date2timestamp(Tools::getSecureGETStringValue("helloWorld_startdate")); // update dataProvider $pluginDataProvider->setParam(PluginDataProviderInterface::PARAM_START_TIMESTAMP, $startTimestamp); $indicator = new HelloWorldIndicator($pluginDataProvider); $indicator->execute(); $data = $indicator->getSmartyVariablesForAjax(); // construct the html table foreach ($data as $smartyKey => $smartyVariable) { $smartyHelper->assign($smartyKey, $smartyVariable); #$logger->debug("key $smartyKey = ".var_export($smartyVariable, true)); } $html = $smartyHelper->fetch(HelloWorldIndicator::getSmartySubFilename()); $data['helloWorld_htmlContent'] = $html; // return html & chart data $jsonData = json_encode($data); echo $jsonData; } else { Tools::sendNotFoundAccess(); } } else { Tools::sendUnauthorizedAccess(); }
$smartyHelper = new SmartyHelper(); if ('getTimetrackDetailsIndicator' == $action) { $startTimestamp = Tools::date2timestamp(Tools::getSecureGETStringValue("timetrackDetails_startdate")); $endTimestamp = Tools::date2timestamp(Tools::getSecureGETStringValue("timetrackDetails_enddate")); $displayedTeam = Tools::getSecureGETIntValue("timetrackDetails_displayedTeam", 0); // update dataProvider $pluginDataProvider->setParam(PluginDataProviderInterface::PARAM_START_TIMESTAMP, $startTimestamp); $pluginDataProvider->setParam(PluginDataProviderInterface::PARAM_END_TIMESTAMP, $endTimestamp); $indicator = new TimetrackDetailsIndicator($pluginDataProvider); // override plugin settings with current attributes $indicator->setPluginSettings(array(TimetrackDetailsIndicator::OPTION_DISPLAYED_TEAM => $displayedTeam)); $indicator->execute(); $data = $indicator->getSmartyVariablesForAjax(); // construct the html table foreach ($data as $smartyKey => $smartyVariable) { $smartyHelper->assign($smartyKey, $smartyVariable); } $html = $smartyHelper->fetch(TimetrackDetailsIndicator::getSmartySubFilename()); $data['timetrackDetails_htmlContent'] = $html; // set JS libraries that must be load $data['timetrackDetails_jsFiles'] = TimetrackDetailsIndicator::getJsFiles(); $data['timetrackDetails_cssFiles'] = TimetrackDetailsIndicator::getCssFiles(); // return html & chart data $jsonData = json_encode($data); echo $jsonData; } else { Tools::sendNotFoundAccess(); } } else { Tools::sendUnauthorizedAccess(); }