mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
N°8796 - Add PHP code style validation in iTop and extensions - format whole code base
This commit is contained in:
328
pages/audit.php
328
pages/audit.php
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
@@ -30,44 +31,34 @@ use Combodo\iTop\Application\WebPage\iTopWebPage;
|
||||
*/
|
||||
function FilterByContext(DBSearch &$oFilter, ApplicationContext $oAppContext)
|
||||
{
|
||||
$sObjClass = $oFilter->GetClass();
|
||||
$sObjClass = $oFilter->GetClass();
|
||||
$aContextParams = $oAppContext->GetNames();
|
||||
$aCallSpec = array($sObjClass, 'MapContextParam');
|
||||
if (is_callable($aCallSpec))
|
||||
{
|
||||
foreach($aContextParams as $sParamName)
|
||||
{
|
||||
$aCallSpec = [$sObjClass, 'MapContextParam'];
|
||||
if (is_callable($aCallSpec)) {
|
||||
foreach ($aContextParams as $sParamName) {
|
||||
$sValue = $oAppContext->GetCurrentValue($sParamName, null);
|
||||
if ($sValue != null)
|
||||
{
|
||||
if ($sValue != null) {
|
||||
$sAttCode = call_user_func($aCallSpec, $sParamName); // Returns null when there is no mapping for this parameter
|
||||
if ( ($sAttCode != null) && MetaModel::IsValidAttCode($sObjClass, $sAttCode))
|
||||
{
|
||||
if (($sAttCode != null) && MetaModel::IsValidAttCode($sObjClass, $sAttCode)) {
|
||||
// Check if the condition points to a hierarchical key
|
||||
$bConditionAdded = false;
|
||||
if ($sAttCode == 'id')
|
||||
{
|
||||
$bConditionAdded = false;
|
||||
if ($sAttCode == 'id') {
|
||||
// Filtering on the objects themselves
|
||||
$sHierarchicalKeyCode = MetaModel::IsHierarchicalClass($sObjClass);
|
||||
|
||||
if ($sHierarchicalKeyCode !== false)
|
||||
{
|
||||
|
||||
if ($sHierarchicalKeyCode !== false) {
|
||||
$oRootFilter = new DBObjectSearch($sObjClass);
|
||||
$oRootFilter->AddCondition($sAttCode, $sValue);
|
||||
$oFilter->AddCondition_PointingTo($oRootFilter, $sHierarchicalKeyCode, TREE_OPERATOR_BELOW); // Use the 'below' operator by default
|
||||
$bConditionAdded = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$oAttDef = MetaModel::GetAttributeDef($sObjClass, $sAttCode);
|
||||
$bConditionAdded = false;
|
||||
if ($oAttDef->IsExternalKey())
|
||||
{
|
||||
if ($oAttDef->IsExternalKey()) {
|
||||
$sHierarchicalKeyCode = MetaModel::IsHierarchicalClass($oAttDef->GetTargetClass());
|
||||
|
||||
if ($sHierarchicalKeyCode !== false)
|
||||
{
|
||||
|
||||
if ($sHierarchicalKeyCode !== false) {
|
||||
$oRootFilter = new DBObjectSearch($oAttDef->GetTargetClass());
|
||||
$oRootFilter->AddCondition('id', $sValue);
|
||||
$oHKFilter = new DBObjectSearch($oAttDef->GetTargetClass());
|
||||
@@ -77,8 +68,7 @@ function FilterByContext(DBSearch &$oFilter, ApplicationContext $oAppContext)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$bConditionAdded)
|
||||
{
|
||||
if (!$bConditionAdded) {
|
||||
$oFilter->AddCondition($sAttCode, $sValue);
|
||||
}
|
||||
}
|
||||
@@ -105,37 +95,28 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext)
|
||||
$oRuleFilter->UpdateContextFromUser();
|
||||
FilterByContext($oRuleFilter, $oAppContext); // Not needed since this filter is a subset of the definition filter, but may speedup things
|
||||
|
||||
if ($oRule->Get('valid_flag') == 'false')
|
||||
{
|
||||
if ($oRule->Get('valid_flag') == 'false') {
|
||||
// The query returns directly the invalid elements
|
||||
$oFilter = $oRuleFilter->Intersect($oDefinitionFilter);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// The query returns only the valid elements, all the others are invalid
|
||||
// Warning : we're generating a `WHERE ID IN`... query, and this could be very slow if there are lots of id !
|
||||
$aValidRows = $oRuleFilter->ToDataArray(array('id'));
|
||||
$aValidIds = array();
|
||||
foreach($aValidRows as $aRow)
|
||||
{
|
||||
$aValidRows = $oRuleFilter->ToDataArray(['id']);
|
||||
$aValidIds = [];
|
||||
foreach ($aValidRows as $aRow) {
|
||||
$aValidIds[] = $aRow['id'];
|
||||
}
|
||||
/** @var \DBObjectSearch $oFilter */
|
||||
$oFilter = $oDefinitionFilter->DeepClone();
|
||||
if (count($aValidIds) > 0)
|
||||
{
|
||||
$aInDefSet = array();
|
||||
foreach($oDefinitionFilter->ToDataArray(array('id')) as $aRow)
|
||||
{
|
||||
if (count($aValidIds) > 0) {
|
||||
$aInDefSet = [];
|
||||
foreach ($oDefinitionFilter->ToDataArray(['id']) as $aRow) {
|
||||
$aInDefSet[] = $aRow['id'];
|
||||
}
|
||||
$aInvalids = array_diff($aInDefSet, $aValidIds);
|
||||
if (count($aInvalids) > 0)
|
||||
{
|
||||
if (count($aInvalids) > 0) {
|
||||
$oFilter->AddConditionForInOperatorUsingParam('id', $aInvalids, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$oFilter->AddCondition('id', 0, '=');
|
||||
}
|
||||
}
|
||||
@@ -143,8 +124,7 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext)
|
||||
return $oFilter;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
require_once('../approot.inc.php');
|
||||
require_once(APPROOT.'/application/application.inc.php');
|
||||
require_once(APPROOT.'/application/startup.inc.php');
|
||||
@@ -153,85 +133,77 @@ try
|
||||
$bSelectionAuditRulesByDefault = utils::GetConfig()->Get('audit.enable_selection_landing_page');
|
||||
$operation = utils::ReadParam('operation', $bSelectionAuditRulesByDefault ? 'selection' : 'audit');
|
||||
$oAppContext = new ApplicationContext();
|
||||
|
||||
|
||||
require_once(APPROOT.'/application/loginwebpage.class.inc.php');
|
||||
LoginWebPage::DoLogin(); // Check user rights and prompt if needed
|
||||
|
||||
|
||||
$oP = new iTopWebPage(Dict::S('UI:Audit:Title'));
|
||||
|
||||
switch($operation)
|
||||
{
|
||||
switch ($operation) {
|
||||
case 'csv':
|
||||
$oP->DisableBreadCrumb();
|
||||
// Big result sets cause long OQL that cannot be passed (serialized) as a GET parameter
|
||||
// Therefore we don't use the standard "search_oql" operation of UI.php to display the CSV
|
||||
$iCategory = utils::ReadParam('category', '');
|
||||
$iRuleIndex = utils::ReadParam('rule', 0);
|
||||
|
||||
$oAuditCategory = MetaModel::GetObject('AuditCategory', $iCategory);
|
||||
$oDefinitionFilter = DBObjectSearch::FromOQL($oAuditCategory->Get('definition_set'));
|
||||
$oDefinitionFilter->UpdateContextFromUser();
|
||||
FilterByContext($oDefinitionFilter, $oAppContext);
|
||||
$oDefinitionSet = new CMDBObjectSet($oDefinitionFilter);
|
||||
$oFilter = GetRuleResultFilter($iRuleIndex, $oDefinitionFilter, $oAppContext);
|
||||
$oErrorObjectSet = new CMDBObjectSet($oFilter);
|
||||
$oAuditRule = MetaModel::GetObject('AuditRule', $iRuleIndex);
|
||||
$sFileName = utils::ReadParam('filename', null, true, 'string');
|
||||
$bAdvanced = utils::ReadParam('advanced', false);
|
||||
$sAdvanced = $bAdvanced ? '&advanced=1' : '';
|
||||
|
||||
if ($sFileName != null)
|
||||
{
|
||||
$oP = new CSVPage("iTop - Export");
|
||||
$sCharset = MetaModel::GetConfig()->Get('csv_file_default_charset');
|
||||
$sCSVData = cmdbAbstractObject::GetSetAsCSV($oErrorObjectSet, array('localize_values' => true, 'fields_advanced' => $bAdvanced), $sCharset);
|
||||
if ($sCharset == 'UTF-8')
|
||||
{
|
||||
$sOutputData = UTF8_BOM.$sCSVData;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sOutputData = $sCSVData;
|
||||
}
|
||||
if ($sFileName == '')
|
||||
{
|
||||
// Plain text => Firefox will NOT propose to download the file
|
||||
$oP->add_header("Content-type: text/plain; charset=$sCharset");
|
||||
}
|
||||
else
|
||||
{
|
||||
$sCSVName = basename($sFileName); // pseudo sanitization, just in case
|
||||
// Force the name of the downloaded file, since windows gives precedence to the extension over of the mime type
|
||||
$oP->add_header("Content-disposition: attachment; filename=\"$sCSVName\"");
|
||||
$oP->add_header("Content-type: text/csv; charset=$sCharset");
|
||||
}
|
||||
$oP->add($sOutputData);
|
||||
$oP->TrashUnexpectedOutput();
|
||||
$oP->output();
|
||||
exit;
|
||||
} else {
|
||||
$sTitle = Dict::S('UI:Audit:AuditErrors');
|
||||
$oP->SetBreadCrumbEntry('ui-tool-auditerrors', $sTitle, '', '', 'fas fa-stethoscope', iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES);
|
||||
$oP->DisableBreadCrumb();
|
||||
// Big result sets cause long OQL that cannot be passed (serialized) as a GET parameter
|
||||
// Therefore we don't use the standard "search_oql" operation of UI.php to display the CSV
|
||||
$iCategory = utils::ReadParam('category', '');
|
||||
$iRuleIndex = utils::ReadParam('rule', 0);
|
||||
|
||||
$oBackButton = ButtonUIBlockFactory::MakeIconLink('fas fa-chevron-left', Dict::S('UI:Audit:InteractiveAudit:Back'), "./audit.php?".$oAppContext->GetForLink());
|
||||
$oP->AddUiBlock($oBackButton);
|
||||
$oP->AddUiBlock(TitleUIBlockFactory::MakeForPage($sTitle.$oAuditRule->Get('description')));
|
||||
$oAuditCategory = MetaModel::GetObject('AuditCategory', $iCategory);
|
||||
$oDefinitionFilter = DBObjectSearch::FromOQL($oAuditCategory->Get('definition_set'));
|
||||
$oDefinitionFilter->UpdateContextFromUser();
|
||||
FilterByContext($oDefinitionFilter, $oAppContext);
|
||||
$oDefinitionSet = new CMDBObjectSet($oDefinitionFilter);
|
||||
$oFilter = GetRuleResultFilter($iRuleIndex, $oDefinitionFilter, $oAppContext);
|
||||
$oErrorObjectSet = new CMDBObjectSet($oFilter);
|
||||
$oAuditRule = MetaModel::GetObject('AuditRule', $iRuleIndex);
|
||||
$sFileName = utils::ReadParam('filename', null, true, 'string');
|
||||
$bAdvanced = utils::ReadParam('advanced', false);
|
||||
$sAdvanced = $bAdvanced ? '&advanced=1' : '';
|
||||
|
||||
$sBlockId = 'audit_errors';
|
||||
$oP->p("<div id=\"$sBlockId\">");
|
||||
$oBlock = DisplayBlock::FromObjectSet($oErrorObjectSet, 'csv', array('show_obsolete_data' => true));
|
||||
$oBlock->Display($oP, 1);
|
||||
$oP->p("</div>");
|
||||
// Adjust the size of the Textarea containing the CSV to fit almost all the remaining space
|
||||
$oP->add_ready_script(" $('#1>textarea').height(400);"); // adjust the size of the block
|
||||
$sExportUrl = utils::GetAbsoluteUrlAppRoot()."pages/audit.php?operation=csv&category=".$oAuditCategory->GetKey()."&rule=".$oAuditRule->GetKey();
|
||||
$oDownloadButton = ButtonUIBlockFactory::MakeForAlternativePrimaryAction('fas fa-chevron-left', Dict::S('UI:Audit:InteractiveAudit:Back'), "./audit.php?".$oAppContext->GetForLink());
|
||||
if ($sFileName != null) {
|
||||
$oP = new CSVPage("iTop - Export");
|
||||
$sCharset = MetaModel::GetConfig()->Get('csv_file_default_charset');
|
||||
$sCSVData = cmdbAbstractObject::GetSetAsCSV($oErrorObjectSet, ['localize_values' => true, 'fields_advanced' => $bAdvanced], $sCharset);
|
||||
if ($sCharset == 'UTF-8') {
|
||||
$sOutputData = UTF8_BOM.$sCSVData;
|
||||
} else {
|
||||
$sOutputData = $sCSVData;
|
||||
}
|
||||
if ($sFileName == '') {
|
||||
// Plain text => Firefox will NOT propose to download the file
|
||||
$oP->add_header("Content-type: text/plain; charset=$sCharset");
|
||||
} else {
|
||||
$sCSVName = basename($sFileName); // pseudo sanitization, just in case
|
||||
// Force the name of the downloaded file, since windows gives precedence to the extension over of the mime type
|
||||
$oP->add_header("Content-disposition: attachment; filename=\"$sCSVName\"");
|
||||
$oP->add_header("Content-type: text/csv; charset=$sCharset");
|
||||
}
|
||||
$oP->add($sOutputData);
|
||||
$oP->TrashUnexpectedOutput();
|
||||
$oP->output();
|
||||
exit;
|
||||
} else {
|
||||
$sTitle = Dict::S('UI:Audit:AuditErrors');
|
||||
$oP->SetBreadCrumbEntry('ui-tool-auditerrors', $sTitle, '', '', 'fas fa-stethoscope', iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES);
|
||||
|
||||
$oBackButton = ButtonUIBlockFactory::MakeIconLink('fas fa-chevron-left', Dict::S('UI:Audit:InteractiveAudit:Back'), "./audit.php?".$oAppContext->GetForLink());
|
||||
$oP->AddUiBlock($oBackButton);
|
||||
$oP->AddUiBlock(TitleUIBlockFactory::MakeForPage($sTitle.$oAuditRule->Get('description')));
|
||||
|
||||
$sBlockId = 'audit_errors';
|
||||
$oP->p("<div id=\"$sBlockId\">");
|
||||
$oBlock = DisplayBlock::FromObjectSet($oErrorObjectSet, 'csv', ['show_obsolete_data' => true]);
|
||||
$oBlock->Display($oP, 1);
|
||||
$oP->p("</div>");
|
||||
// Adjust the size of the Textarea containing the CSV to fit almost all the remaining space
|
||||
$oP->add_ready_script(" $('#1>textarea').height(400);"); // adjust the size of the block
|
||||
$sExportUrl = utils::GetAbsoluteUrlAppRoot()."pages/audit.php?operation=csv&category=".$oAuditCategory->GetKey()."&rule=".$oAuditRule->GetKey();
|
||||
$oDownloadButton = ButtonUIBlockFactory::MakeForAlternativePrimaryAction('fas fa-chevron-left', Dict::S('UI:Audit:InteractiveAudit:Back'), "./audit.php?".$oAppContext->GetForLink());
|
||||
|
||||
$oP->add_ready_script("$('a[href*=\"webservices/export.php?expression=\"]').attr('href', '".$sExportUrl."&filename=audit.csv".$sAdvanced."');");
|
||||
$oP->add_ready_script("$('#1 :checkbox').removeAttr('onclick').on('click', function() { var sAdvanced = ''; if (this.checked) sAdvanced = '&advanced=1'; window.location.href='$sExportUrl'+sAdvanced; } );");
|
||||
}
|
||||
break;
|
||||
|
||||
$oP->add_ready_script("$('a[href*=\"webservices/export.php?expression=\"]').attr('href', '".$sExportUrl."&filename=audit.csv".$sAdvanced."');");
|
||||
$oP->add_ready_script("$('#1 :checkbox').removeAttr('onclick').on('click', function() { var sAdvanced = ''; if (this.checked) sAdvanced = '&advanced=1'; window.location.href='$sExportUrl'+sAdvanced; } );");
|
||||
}
|
||||
break;
|
||||
|
||||
case 'errors':
|
||||
$sTitle = Dict::S('UI:Audit:AuditErrors');
|
||||
$iCategory = utils::ReadParam('category', '');
|
||||
@@ -253,7 +225,7 @@ try
|
||||
$oP->AddUiBlock(TitleUIBlockFactory::MakeForPage($sTitle.$oAuditRule->Get('description')));
|
||||
$sBlockId = 'audit_errors';
|
||||
$oP->p("<div id=\"$sBlockId\">");
|
||||
$oBlock = DisplayBlock::FromObjectSet($oErrorObjectSet, 'list', array('show_obsolete_data' => true));
|
||||
$oBlock = DisplayBlock::FromObjectSet($oErrorObjectSet, 'list', ['show_obsolete_data' => true]);
|
||||
$oBlock->Display($oP, 1);
|
||||
$oP->p("</div>");
|
||||
$sExportUrl = utils::GetAbsoluteUrlAppRoot()."pages/audit.php?operation=csv&category=".$oAuditCategory->GetKey()."&rule=".$oAuditRule->GetKey();
|
||||
@@ -299,13 +271,13 @@ try
|
||||
|
||||
// Fetch all audit domains with at least on linked category
|
||||
$oDomainSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT AuditDomain AS domain JOIN lnkAuditCategoryToAuditDomain AS lnk ON lnk.domain_id = domain.id"));
|
||||
$oDomainSet->SetOrderBy(array('name' => true));
|
||||
$oDomainSet->SetOrderBy(['name' => true]);
|
||||
$iDomainCnt = 0;
|
||||
/** @var AuditDomain $oAuditDomain */
|
||||
while($oAuditDomain = $oDomainSet->Fetch()) {
|
||||
while ($oAuditDomain = $oDomainSet->Fetch()) {
|
||||
$sDomainUrl = utils::GetAbsoluteUrlAppRoot()."pages/audit.php?operation=audit&domain=".$oAuditDomain->GetKey();
|
||||
$sIconUrl = utils::GetAbsoluteUrlAppRoot().'images/icons/icons8-puzzle.svg';
|
||||
/** @var \ormDocument $oImage */
|
||||
/** @var \ormDocument $oImage */
|
||||
$oImage = $oAuditDomain->Get('icon');
|
||||
if (!$oImage->IsEmpty()) {
|
||||
$sIconUrl = $oImage->GetDisplayURL(get_class($oAuditDomain), $oAuditDomain->GetKey(), 'icon');
|
||||
@@ -333,7 +305,7 @@ try
|
||||
$sBreadCrumbTooltip = Dict::S('UI:Audit:Interactive:All:BreadCrumb+');
|
||||
|
||||
if (!empty($sCategories)) { // Case with a set of categories
|
||||
$oCategoriesSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT AuditCategory WHERE id IN (:categories)", array('categories' => explode(',', $sCategories))));
|
||||
$oCategoriesSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT AuditCategory WHERE id IN (:categories)", ['categories' => explode(',', $sCategories)]));
|
||||
$sCategories = implode(", ", $oCategoriesSet->GetColumnAsArray('name'));
|
||||
$oCategoriesSet->Rewind();
|
||||
$sTitle = Dict::Format('UI:Audit:Interactive:Categories:Title', $sCategories);
|
||||
@@ -343,7 +315,7 @@ try
|
||||
|
||||
} elseif (!empty($sDomainKey)) { // Case with a single Domain
|
||||
$oAuditDomain = MetaModel::GetObject('AuditDomain', $sDomainKey);
|
||||
$oCategoriesSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT AuditCategory AS c JOIN lnkAuditCategoryToAuditDomain AS lnk ON lnk.category_id = c.id WHERE lnk.domain_id = :domain", array('domain' => $oAuditDomain->GetKey())));
|
||||
$oCategoriesSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT AuditCategory AS c JOIN lnkAuditCategoryToAuditDomain AS lnk ON lnk.category_id = c.id WHERE lnk.domain_id = :domain", ['domain' => $oAuditDomain->GetKey()]));
|
||||
$sDomainName = $oAuditDomain->GetName();
|
||||
$sTitle = Dict::Format('UI:Audit:Interactive:Domain:Title', $sDomainName);
|
||||
$sSubTitle = Dict::Format('UI:Audit:Interactive:Domain:SubTitle', $sDomainName);
|
||||
@@ -400,16 +372,16 @@ try
|
||||
// Add a button in the above toolbar
|
||||
$sAuditCategoryClass = get_class($oAuditCategory);
|
||||
if (UserRights::IsActionAllowed($sAuditCategoryClass, UR_ACTION_READ)) {
|
||||
$oToolbar->AddSubBlock(ButtonUIBlockFactory::MakeIconLink('fas fa-wrench fa-lg', Dict::S('UI:Audit:ViewRules'), ApplicationContext::MakeObjectUrl($sAuditCategoryClass, $oAuditCategory->GetKey()).'&#ObjectProperties=tab_ClassAuditCategoryAttributerules_list'),);
|
||||
$oToolbar->AddSubBlock(ButtonUIBlockFactory::MakeIconLink('fas fa-wrench fa-lg', Dict::S('UI:Audit:ViewRules'), ApplicationContext::MakeObjectUrl($sAuditCategoryClass, $oAuditCategory->GetKey()).'&#ObjectProperties=tab_ClassAuditCategoryAttributerules_list'), );
|
||||
}
|
||||
$aResults = array();
|
||||
$aResults = [];
|
||||
try {
|
||||
$iCount = 0;
|
||||
$oDefinitionFilter = DBObjectSearch::FromOQL($oAuditCategory->Get('definition_set'));
|
||||
$oDefinitionFilter->UpdateContextFromUser();
|
||||
FilterByContext($oDefinitionFilter, $oAppContext);
|
||||
|
||||
$aObjectsWithErrors = array();
|
||||
$aObjectsWithErrors = [];
|
||||
if (!empty($currentOrganization)) {
|
||||
if (MetaModel::IsValidFilterCode($oDefinitionFilter->GetClass(), 'org_id')) {
|
||||
$oDefinitionFilter->AddCondition('org_id', $currentOrganization, '=');
|
||||
@@ -421,7 +393,7 @@ try
|
||||
$oRulesFilter->AddCondition('category_id', $oAuditCategory->GetKey(), '=');
|
||||
$oRulesSet = new DBObjectSet($oRulesFilter);
|
||||
while ($oAuditRule = $oRulesSet->fetch()) {
|
||||
$aRow = array();
|
||||
$aRow = [];
|
||||
$aRow['description'] = $oAuditRule->GetName();
|
||||
if ($iCount == 0) {
|
||||
// nothing to check, really !
|
||||
@@ -431,16 +403,15 @@ try
|
||||
} else {
|
||||
try {
|
||||
$oFilter = GetRuleResultFilter($oAuditRule->GetKey(), $oDefinitionFilter, $oAppContext);
|
||||
$aErrors = $oFilter->SelectAttributeToArray('id');
|
||||
$aErrors = $oFilter->SelectAttributeToArray('id');
|
||||
$iErrorsCount = count($aErrors);
|
||||
foreach ($aErrors as $aErrorRow) {
|
||||
$aObjectsWithErrors[$aErrorRow['id']] = true;
|
||||
}
|
||||
$aRow['nb_errors'] = ($iErrorsCount == 0) ? '0' : "<a href=\"?operation=errors&category=".$oAuditCategory->GetKey()."&rule=".$oAuditRule->GetKey().$oAppContext->GetForLink(true)."\">$iErrorsCount</a> <a href=\"?operation=csv&category=".$oAuditCategory->GetKey()."&rule=".$oAuditRule->GetKey().$oAppContext->GetForLink(true)."\"><img src=\"" . utils::GetAbsoluteUrlAppRoot() . "images/icons/icons8-export-csv.svg\" class=\"ibo-audit--audit-line--csv-download\"></a>";
|
||||
$aRow['nb_errors'] = ($iErrorsCount == 0) ? '0' : "<a href=\"?operation=errors&category=".$oAuditCategory->GetKey()."&rule=".$oAuditRule->GetKey().$oAppContext->GetForLink(true)."\">$iErrorsCount</a> <a href=\"?operation=csv&category=".$oAuditCategory->GetKey()."&rule=".$oAuditRule->GetKey().$oAppContext->GetForLink(true)."\"><img src=\"".utils::GetAbsoluteUrlAppRoot()."images/icons/icons8-export-csv.svg\" class=\"ibo-audit--audit-line--csv-download\"></a>";
|
||||
$aRow['percent_ok'] = sprintf('%.2f', 100.0 * (($iCount - $iErrorsCount) / $iCount));
|
||||
$aRow['class'] = $oAuditCategory->GetReportColor($iCount, $iErrorsCount);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$aRow['nb_errors'] = Dict::S('UI:Audit:OqlError');
|
||||
$aRow['percent_ok'] = Dict::S('UI:Audit:Error:ValueNA');
|
||||
$aRow['class'] = 'red';
|
||||
@@ -462,57 +433,50 @@ try
|
||||
$oWorkingBlock->SetCount((int)$oWorkingBlock->GetCount() + ($iCount - $iTotalErrors));
|
||||
$oAuditCategoryPanelBlock->SetSubTitle(Dict::Format('UI:Audit:AuditCategory:Subtitle', $iTotalErrors, $iCount, $sOverallPercentOk));
|
||||
|
||||
} catch (Exception $e) {
|
||||
$sMessage = Dict::Format('UI:Audit:ErrorIn_Category_Reason', $oAuditCategory->GetHyperlink(), utils::HtmlEntities($e->getMessage()));
|
||||
$oErrorAlert = AlertUIBlockFactory::MakeForFailure(Dict::S('UI:Audit:ErrorIn_Category'), $sMessage);
|
||||
$oErrorAlert->AddCSSClass('ibo-audit--error-alert');
|
||||
$oP->AddUiBlock($oErrorAlert);
|
||||
continue;
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
$sMessage = Dict::Format('UI:Audit:ErrorIn_Category_Reason', $oAuditCategory->GetHyperlink(), utils::HtmlEntities($e->getMessage()));
|
||||
$oErrorAlert = AlertUIBlockFactory::MakeForFailure(Dict::S('UI:Audit:ErrorIn_Category'), $sMessage);
|
||||
$oErrorAlert->AddCSSClass('ibo-audit--error-alert');
|
||||
$oP->AddUiBlock($oErrorAlert);
|
||||
continue;
|
||||
|
||||
$oAuditCategoryPanelBlock->SetColorFromColorSemantic($sClass);
|
||||
$oAuditCategoryPanelBlock->AddCSSClass('ibo-audit--audit-category--panel');
|
||||
$aData = [];
|
||||
foreach ($aResults as $aRow) {
|
||||
$aData[] = [
|
||||
'audit_rule' => $aRow['description'],
|
||||
'nb_err' => $aRow['nb_errors'],
|
||||
'percentage_ok' => $aRow['percent_ok'],
|
||||
'@class' => 'ibo-is-'.$aRow['class'].'',
|
||||
];
|
||||
}
|
||||
|
||||
$aAttribs = [
|
||||
'audit_rule' => ['label' => Dict::S('UI:Audit:HeaderAuditRule'), 'description' => Dict::S('UI:Audit:HeaderAuditRule')],
|
||||
'nb_err' => ['label' => Dict::S('UI:Audit:HeaderNbErrors'), 'description' => Dict::S('UI:Audit:HeaderNbErrors')],
|
||||
'percentage_ok' => ['label' => Dict::S('UI:Audit:PercentageOk'), 'description' => Dict::S('UI:Audit:PercentageOk')],
|
||||
];
|
||||
|
||||
$oAttachmentTableBlock = DataTableUIBlockFactory::MakeForStaticData('', $aAttribs, $aData, null, [], "", ['pageLength' => -1]);
|
||||
$oAuditCategoryPanelBlock->AddSubBlock($oAttachmentTableBlock);
|
||||
$aAuditCategoryPanels[] = $oAuditCategoryPanelBlock;
|
||||
}
|
||||
|
||||
$oAuditCategoryPanelBlock->SetColorFromColorSemantic($sClass);
|
||||
$oAuditCategoryPanelBlock->AddCSSClass('ibo-audit--audit-category--panel');
|
||||
$aData = [];
|
||||
foreach($aResults as $aRow)
|
||||
{
|
||||
$aData[] = array(
|
||||
'audit_rule' => $aRow['description'],
|
||||
'nb_err' => $aRow['nb_errors'],
|
||||
'percentage_ok' => $aRow['percent_ok'],
|
||||
'@class' => 'ibo-is-'.$aRow['class'].'',
|
||||
);
|
||||
foreach ($aAuditCategoryPanels as $oAuditCategoryPanel) {
|
||||
$oP->AddUiBlock($oAuditCategoryPanel);
|
||||
}
|
||||
|
||||
$aAttribs = array(
|
||||
'audit_rule' => array('label' => Dict::S('UI:Audit:HeaderAuditRule'), 'description' => Dict::S('UI:Audit:HeaderAuditRule')),
|
||||
'nb_err' => array('label' => Dict::S('UI:Audit:HeaderNbErrors'), 'description' => Dict::S('UI:Audit:HeaderNbErrors')),
|
||||
'percentage_ok' => array('label' => Dict::S('UI:Audit:PercentageOk'), 'description' => Dict::S('UI:Audit:PercentageOk')),
|
||||
);
|
||||
|
||||
$oAttachmentTableBlock = DataTableUIBlockFactory::MakeForStaticData('', $aAttribs, $aData, null, [], "", array('pageLength' => -1));
|
||||
$oAuditCategoryPanelBlock->AddSubBlock($oAttachmentTableBlock);
|
||||
$aAuditCategoryPanels[] = $oAuditCategoryPanelBlock;
|
||||
}
|
||||
foreach ($aAuditCategoryPanels as $oAuditCategoryPanel) {
|
||||
$oP->AddUiBlock($oAuditCategoryPanel);
|
||||
}
|
||||
}
|
||||
$oP->output();
|
||||
}
|
||||
catch(CoreException $e)
|
||||
{
|
||||
} catch (CoreException $e) {
|
||||
require_once(APPROOT.'/setup/setuppage.class.inc.php');
|
||||
$oP = new ErrorPage(Dict::S('UI:PageTitle:FatalError'));
|
||||
$oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
|
||||
$oP->error(Dict::Format('UI:Error_Details', $e->getHtmlDesc()));
|
||||
$oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
|
||||
$oP->error(Dict::Format('UI:Error_Details', $e->getHtmlDesc()));
|
||||
$oP->output();
|
||||
|
||||
if (MetaModel::IsLogEnabledIssue())
|
||||
{
|
||||
if (MetaModel::IsValidClass('EventIssue'))
|
||||
{
|
||||
if (MetaModel::IsLogEnabledIssue()) {
|
||||
if (MetaModel::IsValidClass('EventIssue')) {
|
||||
$oLog = new EventIssue();
|
||||
|
||||
$oLog->Set('message', $e->getMessage());
|
||||
@@ -529,19 +493,15 @@ catch(CoreException $e)
|
||||
|
||||
// For debugging only
|
||||
//throw $e;
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
} catch (Exception $e) {
|
||||
require_once(APPROOT.'/setup/setuppage.class.inc.php');
|
||||
$oP = new ErrorPage(Dict::S('UI:PageTitle:FatalError'));
|
||||
$oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
|
||||
$oP->error(Dict::Format('UI:Error_Details', $e->getMessage()));
|
||||
$oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
|
||||
$oP->error(Dict::Format('UI:Error_Details', $e->getMessage()));
|
||||
$oP->output();
|
||||
|
||||
if (MetaModel::IsLogEnabledIssue())
|
||||
{
|
||||
if (MetaModel::IsValidClass('EventIssue'))
|
||||
{
|
||||
if (MetaModel::IsLogEnabledIssue()) {
|
||||
if (MetaModel::IsValidClass('EventIssue')) {
|
||||
$oLog = new EventIssue();
|
||||
|
||||
$oLog->Set('message', $e->getMessage());
|
||||
@@ -549,7 +509,7 @@ catch(Exception $e)
|
||||
$oLog->Set('issue', 'PHP Exception');
|
||||
$oLog->Set('impact', 'Page could not be displayed');
|
||||
$oLog->Set('callstack', $e->getTrace());
|
||||
$oLog->Set('data', array());
|
||||
$oLog->Set('data', []);
|
||||
$oLog->DBInsertNoReload();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user