public function output() { if (class_exists('DBSearch')) { DBSearch::RecordQueryTrace(); } if (class_exists('ExecutionKPI')) { ExecutionKPI::ReportStats(); } }
public function output() { if (class_exists('MetaModel')) { MetaModel::RecordQueryTrace(); } if (class_exists('ExecutionKPI')) { ExecutionKPI::ReportStats(); } }
public function output() { $this->add_header("Content-Length: " . strlen(trim($this->s_content))); foreach ($this->a_headers as $s_header) { header($s_header); } echo trim($this->s_content); echo "\n"; if (class_exists('MetaModel')) { MetaModel::RecordQueryTrace(); } if (class_exists('ExecutionKPI')) { ExecutionKPI::ReportStats(); } }
public function output() { $this->add_header("Content-Length: " . strlen(trim($this->s_content))); // Get the unexpected output but do nothing with it $sTrash = $this->ob_get_clean_safe(); foreach ($this->a_headers as $s_header) { header($s_header); } echo trim($this->s_content); echo "\n"; if (class_exists('DBSearch')) { DBSearch::RecordQueryTrace(); } if (class_exists('ExecutionKPI')) { ExecutionKPI::ReportStats(); } }
/** * Outputs (via some echo) the complete HTML page by assembling all its elements */ public function output() { $sAbsURLAppRoot = addslashes($this->m_sRootUrl); //$this->set_base($this->m_sRootUrl.'pages/'); $sForm = $this->GetSiloSelectionForm(); $this->DisplayMenu(); // Compute the menu // Call the extensions to add content to the page, so that they can also add styles or scripts $sBannerExtraHtml = ''; foreach (MetaModel::EnumPlugins('iPageUIExtension') as $oExtensionInstance) { $sBannerExtraHtml .= $oExtensionInstance->GetBannerHtml($this); } $sNorthPane = ''; foreach (MetaModel::EnumPlugins('iPageUIExtension') as $oExtensionInstance) { $sNorthPane .= $oExtensionInstance->GetNorthPaneHtml($this); } if (UserRights::IsAdministrator() && ExecutionKPI::IsEnabled()) { $sNorthPane .= '<div id="admin-banner"><span style="padding:5px;">' . ExecutionKPI::GetDescription() . '<span></div>'; } //$sSouthPane = '<p>Peak memory Usage: '.sprintf('%.3f MB', memory_get_peak_usage(true) / (1024*1024)).'</p>'; $sSouthPane = ''; foreach (MetaModel::EnumPlugins('iPageUIExtension') as $oExtensionInstance) { $sSouthPane .= $oExtensionInstance->GetSouthPaneHtml($this); } // Put here the 'ready scripts' that must be executed after all others $aMultiselectOptions = array('header' => true, 'checkAllText' => Dict::S('UI:SearchValue:CheckAll'), 'uncheckAllText' => Dict::S('UI:SearchValue:UncheckAll'), 'noneSelectedText' => Dict::S('UI:SearchValue:Any'), 'selectedText' => Dict::S('UI:SearchValue:NbSelected'), 'selectedList' => 1); $sJSMultiselectOptions = json_encode($aMultiselectOptions); $this->add_ready_script(<<<EOF \t\t// Since the event is only triggered when the hash changes, we need to trigger \t\t// the event now, to handle the hash the page may have loaded with. \t\t\$(window).trigger( 'hashchange' ); \t\t \t\t// Some table are sort-able, some are not, let's fix this \t\t\$('table.listResults').each( function() { FixTableSorter(\$(this)); } ); \t\t \t\t\$('.multiselect').multiselect({$sJSMultiselectOptions}); \t\tFixSearchFormsDisposition(); EOF ); if ($this->GetOutputFormat() == 'html') { foreach ($this->a_headers as $s_header) { header($s_header); } } $s_captured_output = $this->ob_get_clean_safe(); $sHtml = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"; $sHtml .= "<html>\n"; $sHtml .= "<head>\n"; // Make sure that Internet Explorer renders the page using its latest/highest/greatest standards ! $sHtml .= "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n"; $sHtml .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"; $sHtml .= "<title>" . htmlentities($this->s_title, ENT_QUOTES, 'UTF-8') . "</title>\n"; $sHtml .= $this->get_base_tag(); // Stylesheets MUST be loaded before any scripts otherwise // jQuery scripts may face some spurious problems (like failing on a 'reload') foreach ($this->a_linked_stylesheets as $a_stylesheet) { if ($a_stylesheet['condition'] != "") { $sHtml .= "<!--[if {$a_stylesheet['condition']}]>\n"; } $sHtml .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$a_stylesheet['link']}\" />\n"; if ($a_stylesheet['condition'] != "") { $sHtml .= "<![endif]-->\n"; } } // special stylesheet for printing, hides the navigation gadgets $sHtml .= "<link rel=\"stylesheet\" media=\"print\" type=\"text/css\" href=\"../css/print.css\" />\n"; if ($this->GetOutputFormat() == 'html') { $sHtml .= $this->output_dict_entries(true); // before any script so that they can benefit from the translations foreach ($this->a_linked_scripts as $s_script) { // Make sure that the URL to the script contains the application's version number // so that the new script do NOT get reloaded from the cache when the application is upgraded if (strpos($s_script, '?') === false) { $s_script .= "?itopversion=" . ITOP_VERSION; } else { $s_script .= "&itopversion=" . ITOP_VERSION; } $sHtml .= "<script type=\"text/javascript\" src=\"{$s_script}\"></script>\n"; } $this->add_script("var iPaneVisWatchDog = window.setTimeout('FixPaneVis()',5000);\n\$(document).ready(function() {\n{$this->m_sInitScript};\nwindow.setTimeout('onDelayedReady()',10)\n});"); if (count($this->m_aReadyScripts) > 0) { $this->add_script("\nonDelayedReady = function() {\n" . implode("\n", $this->m_aReadyScripts) . "\n}\n"); } if (count($this->a_scripts) > 0) { $sHtml .= "<script type=\"text/javascript\">\n"; foreach ($this->a_scripts as $s_script) { $sHtml .= "{$s_script}\n"; } $sHtml .= "</script>\n"; } } if (count($this->a_styles) > 0) { $sHtml .= "<style>\n"; foreach ($this->a_styles as $s_style) { $sHtml .= "{$s_style}\n"; } $sHtml .= "</style>\n"; } $sHtml .= "<link rel=\"search\" type=\"application/opensearchdescription+xml\" title=\"iTop\" href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/opensearch.xml.php\" />\n"; $sHtml .= "<link rel=\"shortcut icon\" href=\"" . utils::GetAbsoluteUrlAppRoot() . "images/favicon.ico\" />\n"; $sHtml .= "</head>\n"; $sHtml .= "<body>\n"; // Render the revision number if (ITOP_REVISION == '$WCREV$') { // This is NOT a version built using the buil system, just display the main version $sVersionString = Dict::Format('UI:iTopVersion:Short', ITOP_VERSION); } else { // This is a build made from SVN, let display the full information $sVersionString = Dict::Format('UI:iTopVersion:Long', ITOP_VERSION, ITOP_REVISION, ITOP_BUILD_DATE); } // Render the text of the global search form $sText = htmlentities(utils::ReadParam('text', '', false, 'raw_data'), ENT_QUOTES, 'UTF-8'); $sOnClick = ""; if (empty($sText)) { // if no search text is supplied then // 1) the search text is filled with "your search" // 2) clicking on it will erase it $sText = Dict::S("UI:YourSearch"); $sOnClick = " onclick=\"this.value='';this.onclick=null;\""; } // Render the tabs in the page (if any) $this->s_content = $this->m_oTabs->RenderIntoContent($this->s_content); if ($this->GetOutputFormat() == 'html') { $oAppContext = new ApplicationContext(); $sUserName = UserRights::GetUser(); $sIsAdmin = UserRights::IsAdministrator() ? '(Administrator)' : ''; if (UserRights::IsAdministrator()) { $sLogonMessage = Dict::Format('UI:LoggedAsMessage+Admin', $sUserName); } else { $sLogonMessage = Dict::Format('UI:LoggedAsMessage', $sUserName); } $sLogOffMenu = "<span id=\"logOffBtn\"><ul><li><img src=\"../images/onOffBtn.png\"><ul>"; $sLogOffMenu .= "<li><span>{$sLogonMessage}</span></li>\n"; $aActions = array(); $oPrefs = new URLPopupMenuItem('UI:Preferences', Dict::S('UI:Preferences'), utils::GetAbsoluteUrlAppRoot() . "pages/preferences.php?" . $oAppContext->GetForLink()); $aActions[$oPrefs->GetUID()] = $oPrefs->GetMenuItem(); if (utils::CanLogOff()) { $oLogOff = new URLPopupMenuItem('UI:LogOffMenu', Dict::S('UI:LogOffMenu'), utils::GetAbsoluteUrlAppRoot() . 'pages/logoff.php?operation=do_logoff'); $aActions[$oLogOff->GetUID()] = $oLogOff->GetMenuItem(); } if (UserRights::CanChangePassword()) { $oChangePwd = new URLPopupMenuItem('UI:ChangePwdMenu', Dict::S('UI:ChangePwdMenu'), utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?loginop=change_pwd'); $aActions[$oChangePwd->GetUID()] = $oChangePwd->GetMenuItem(); } utils::GetPopupMenuItems($this, iPopupMenuExtension::MENU_USER_ACTIONS, null, $aActions); $oAbout = new JSPopupMenuItem('UI:AboutBox', Dict::S('UI:AboutBox'), 'return ShowAboutBox();'); $aActions[$oAbout->GetUID()] = $oAbout->GetMenuItem(); $sLogOffMenu .= $this->RenderPopupMenuItems($aActions); $sRestrictions = ''; if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE)) { if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE)) { $sRestrictions = Dict::S('UI:AccessRO-All'); } } elseif (!MetaModel::DBHasAccess(ACCESS_USER_WRITE)) { $sRestrictions = Dict::S('UI:AccessRO-Users'); } $sApplicationBanner = ''; if (strlen($sRestrictions) > 0) { $sAdminMessage = trim(MetaModel::GetConfig()->Get('access_message')); $sApplicationBanner .= '<div id="admin-banner">'; $sApplicationBanner .= '<img src="../images/locked.png" style="vertical-align:middle;">'; $sApplicationBanner .= ' <b>' . $sRestrictions . '</b>'; if (strlen($sAdminMessage) > 0) { $sApplicationBanner .= ' <b>' . $sAdminMessage . '</b>'; } $sApplicationBanner .= '</div>'; } if (strlen($this->m_sMessage)) { $sApplicationBanner .= '<div id="admin-banner"><span style="padding:5px;">' . $this->m_sMessage . '<span></div>'; } $sApplicationBanner .= $sBannerExtraHtml; if (!empty($sNorthPane)) { $sNorthPane = '<div id="bottom-pane" class="ui-layout-north">' . $sNorthPane . '</div>'; } if (!empty($sSouthPane)) { $sSouthPane = '<div id="bottom-pane" class="ui-layout-south">' . $sSouthPane . '</div>'; } $sIconUrl = Utils::GetConfig()->Get('app_icon_url'); $sOnlineHelpUrl = MetaModel::GetConfig()->Get('online_help'); //$sLogOffMenu = "<span id=\"logOffBtn\" style=\"height:55px;padding:0;margin:0;\"><img src=\"../images/onOffBtn.png\"></span>"; $sDisplayIcon = utils::GetAbsoluteUrlAppRoot() . 'images/itop-logo.png'; if (file_exists(MODULESROOT . 'branding/main-logo.png')) { $sDisplayIcon = utils::GetAbsoluteUrlModulesRoot() . 'branding/main-logo.png'; } $sHtml .= $sNorthPane; $sHtml .= '<div id="left-pane" class="ui-layout-west">'; $sHtml .= '<!-- Beginning of the left pane -->'; $sHtml .= ' <div class="ui-layout-north">'; $sHtml .= ' <div id="header-logo">'; $sHtml .= ' <div id="top-left"></div><div id="logo"><a href="' . htmlentities($sIconUrl, ENT_QUOTES, 'UTF-8') . '"><img src="' . $sDisplayIcon . '" title="' . htmlentities($sVersionString, ENT_QUOTES, 'UTF-8') . '" style="border:0; margin-top:16px; margin-right:40px;"/></a></div>'; $sHtml .= ' </div>'; $sHtml .= ' <div class="header-menu">'; if (!MetaModel::GetConfig()->Get('demo_mode')) { $sHtml .= ' <div class="icon ui-state-default ui-corner-all"><span id="tPinMenu" class="ui-icon ui-icon-pin-w">pin</span></div>'; } $sHtml .= ' <div style="text-align:center;">' . self::FilterXSS($sForm) . '</div>'; $sHtml .= ' </div>'; $sHtml .= ' </div>'; $sHtml .= ' <div id="menu" class="ui-layout-center">'; $sHtml .= ' <div id="inner_menu">'; $sHtml .= ' <div id="accordion">'; $sHtml .= self::FilterXSS($this->m_sMenu); $sHtml .= ' <!-- Beginning of the accordion menu -->'; $sHtml .= ' <!-- End of the accordion menu-->'; $sHtml .= ' </div>'; $sHtml .= ' </div> <!-- /inner menu -->'; $sHtml .= ' </div> <!-- /menu -->'; $sHtml .= ' <div class="footer ui-layout-south"><div id="combodo_logo"><a href="http://www.combodo.com" title="www.combodo.com" target="_blank"><img src="../images/logo-combodo.png"/></a></div></div>'; $sHtml .= '<!-- End of the left pane -->'; $sHtml .= '</div>'; $sHtml .= '<div class="ui-layout-center">'; $sHtml .= ' <div id="top-bar" style="width:100%">'; $sHtml .= self::FilterXSS($sApplicationBanner); $sHtml .= ' <div id="global-search"><form action="' . utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php"><table><tr><td></td><td id="g-search-input"><input type="text" name="text" value="' . $sText . '"' . $sOnClick . '/></td>'; $sHtml .= '<td><input type="image" src="../images/searchBtn.png"/></a></td>'; $sHtml .= '<td><a style="background:transparent;" href="' . $sOnlineHelpUrl . '" target="_blank"><img style="border:0;padding-left:20px;padding-right:10px;" title="' . Dict::S('UI:Help') . '" src="../images/help.png"/></td>'; $sHtml .= '<td style="padding-right:20px;padding-left:10px;">' . self::FilterXSS($sLogOffMenu) . '</td><td><input type="hidden" name="operation" value="full_text"/></td></tr></table></form></div>'; //echo '<td> <input type="hidden" name="operation" value="full_text"/></td></tr></table></form></div>'; $sHtml .= ' </div>'; $sHtml .= ' <div class="ui-layout-content" style="overflow:auto;">'; $sHtml .= ' <!-- Beginning of page content -->'; $sHtml .= self::FilterXSS($this->s_content); $sHtml .= ' <!-- End of page content -->'; $sHtml .= ' </div>'; $sHtml .= '</div>'; $sHtml .= $sSouthPane; // Add the captured output if (trim($s_captured_output) != "") { $sHtml .= "<div id=\"rawOutput\" title=\"Debug Output\"><div style=\"height:500px; overflow-y:auto;\">" . self::FilterXSS($s_captured_output) . "</div></div>\n"; } $sHtml .= "<div id=\"at_the_end\">" . self::FilterXSS($this->s_deferred_content) . "</div>"; $sHtml .= "<div style=\"display:none\" title=\"ex2\" id=\"ex2\">Please wait...</div>\n"; // jqModal Window $sHtml .= "<div style=\"display:none\" title=\"dialog\" id=\"ModalDlg\"></div>"; $sHtml .= "<div style=\"display:none\" id=\"ajax_content\"></div>"; } else { $sHtml .= self::FilterXSS($this->s_content); } $sHtml .= "</body>\n"; $sHtml .= "</html>\n"; if ($this->GetOutputFormat() == 'html') { $oKPI = new ExecutionKPI(); echo $sHtml; $oKPI->ComputeAndReport('Echoing (' . round(strlen($sHtml) / 1024) . ' Kb)'); } else { if ($this->GetOutputFormat() == 'pdf' && $this->IsOutputFormatAvailable('pdf')) { if (@is_readable(APPROOT . 'lib/MPDF/mpdf.php')) { require_once APPROOT . 'lib/MPDF/mpdf.php'; $oMPDF = new mPDF('c'); $oMPDF->mirroMargins = false; if ($this->a_base['href'] != '') { $oMPDF->setBasePath($this->a_base['href']); // Seems that the <BASE> tag is not recognized by mPDF... } $oMPDF->showWatermarkText = true; if ($this->GetOutputOption('pdf', 'template_path')) { $oMPDF->setImportUse(); // Allow templates $oMPDF->SetDocTemplate($this->GetOutputOption('pdf', 'template_path'), 1); } $oMPDF->WriteHTML($sHtml); $sOutputName = $this->s_title . '.pdf'; if ($this->GetOutputOption('pdf', 'output_name')) { $sOutputName = $this->GetOutputOption('pdf', 'output_name'); } $oMPDF->Output($sOutputName, 'I'); } } } DBSearch::RecordQueryTrace(); ExecutionKPI::ReportStats(); }
protected function GetSQLQuery($aOrderBy, $aArgs, $aAttToLoad, $aExtendedDataSpec, $iLimitCount, $iLimitStart, $bGetCount, $aGroupByExpr = null) { // Hide objects that are not visible to the current user // $oSearch = $this; if (!$this->IsAllDataAllowed() && !$this->IsDataFiltered()) { $oVisibleObjects = UserRights::GetSelectFilter($this->GetClass(), $this->GetModifierProperties('UserRightsGetSelectFilter')); if ($oVisibleObjects === false) { // Make sure this is a valid search object, saying NO for all $oVisibleObjects = DBObjectSearch::FromEmptySet($this->GetClass()); } if (is_object($oVisibleObjects)) { $oSearch = $this->Intersect($oVisibleObjects); $oSearch->SetDataFiltered(); } else { // should be true at this point, meaning that no additional filtering // is required } } // Compute query modifiers properties (can be set in the search itself, by the context, etc.) // $aModifierProperties = MetaModel::MakeModifierProperties($oSearch); // Create a unique cache id // if (self::$m_bQueryCacheEnabled || self::$m_bTraceQueries) { // Need to identify the query $sOqlQuery = $oSearch->ToOql(); if (count($aModifierProperties)) { array_multisort($aModifierProperties); $sModifierProperties = json_encode($aModifierProperties); } else { $sModifierProperties = ''; } $sRawId = $sOqlQuery . $sModifierProperties; if (!is_null($aAttToLoad)) { $sRawId .= json_encode($aAttToLoad); } if (!is_null($aGroupByExpr)) { foreach ($aGroupByExpr as $sAlias => $oExpr) { $sRawId .= 'g:' . $sAlias . '!' . $oExpr->Render(); } } $sRawId .= $bGetCount; $sOqlId = md5($sRawId); } else { $sOqlQuery = "SELECTING... " . $oSearch->GetClass(); $sOqlId = "query id ? n/a"; } // Query caching // if (self::$m_bQueryCacheEnabled) { // Warning: using directly the query string as the key to the hash array can FAIL if the string // is long and the differences are only near the end... so it's safer (but not bullet proof?) // to use a hash (like md5) of the string as the key ! // // Example of two queries that were found as similar by the hash array: // SELECT SLT JOIN lnkSLTToSLA AS L1 ON L1.slt_id=SLT.id JOIN SLA ON L1.sla_id = SLA.id JOIN lnkContractToSLA AS L2 ON L2.sla_id = SLA.id JOIN CustomerContract ON L2.contract_id = CustomerContract.id WHERE SLT.ticket_priority = 1 AND SLA.service_id = 3 AND SLT.metric = 'TTO' AND CustomerContract.customer_id = 2 // and // SELECT SLT JOIN lnkSLTToSLA AS L1 ON L1.slt_id=SLT.id JOIN SLA ON L1.sla_id = SLA.id JOIN lnkContractToSLA AS L2 ON L2.sla_id = SLA.id JOIN CustomerContract ON L2.contract_id = CustomerContract.id WHERE SLT.ticket_priority = 1 AND SLA.service_id = 3 AND SLT.metric = 'TTR' AND CustomerContract.customer_id = 2 // the only difference is R instead or O at position 285 (TTR instead of TTO)... // if (array_key_exists($sOqlId, self::$m_aQueryStructCache)) { // hit! $oSQLQuery = unserialize(serialize(self::$m_aQueryStructCache[$sOqlId])); // Note: cloning is not enough because the subtree is made of objects } elseif (self::$m_bUseAPCCache) { // Note: For versions of APC older than 3.0.17, fetch() accepts only one parameter // $sOqlAPCCacheId = 'itop-' . MetaModel::GetEnvironmentId() . '-query-cache-' . $sOqlId; $oKPI = new ExecutionKPI(); $result = apc_fetch($sOqlAPCCacheId); $oKPI->ComputeStats('Query APC (fetch)', $sOqlQuery); if (is_object($result)) { $oSQLQuery = $result; self::$m_aQueryStructCache[$sOqlId] = $oSQLQuery; } } } if (!isset($oSQLQuery)) { $oKPI = new ExecutionKPI(); $oSQLQuery = $oSearch->MakeSQLQuery($aAttToLoad, $bGetCount, $aModifierProperties, $aGroupByExpr); $oSQLQuery->SetSourceOQL($sOqlQuery); $oKPI->ComputeStats('MakeSQLQuery', $sOqlQuery); if (self::$m_bQueryCacheEnabled) { if (self::$m_bUseAPCCache) { $oKPI = new ExecutionKPI(); apc_store($sOqlAPCCacheId, $oSQLQuery, self::$m_iQueryCacheTTL); $oKPI->ComputeStats('Query APC (store)', $sOqlQuery); } self::$m_aQueryStructCache[$sOqlId] = $oSQLQuery->DeepClone(); } } // Join to an additional table, if required... // if ($aExtendedDataSpec != null) { $sTableAlias = '_extended_data_'; $aExtendedFields = array(); foreach ($aExtendedDataSpec['fields'] as $sColumn) { $sColRef = $oSearch->GetClassAlias() . '_extdata_' . $sColumn; $aExtendedFields[$sColRef] = new FieldExpressionResolved($sColumn, $sTableAlias); } $oSQLQueryExt = new SQLObjectQuery($aExtendedDataSpec['table'], $sTableAlias, $aExtendedFields); $oSQLQuery->AddInnerJoin($oSQLQueryExt, 'id', $aExtendedDataSpec['join_key']); } return $oSQLQuery; }
/** * @param string sUser A user login or * for all users */ public static function SetAllowedUser($sUser) { self::$m_sAllowedUser = $sUser; }
protected function OnUpdate() { $this->TraceToText(); $sMemPeak = max($this->Get('memory_usage_peak'), ExecutionKPI::memory_get_peak_usage()); $this->Set('memory_usage_peak', $sMemPeak); parent::OnUpdate(); }
public function LoadCache() { if (!is_null($this->m_aProfiles)) { return; } // Could be loaded in a shared memory (?) $oKPI = new ExecutionKPI(); if (self::HasSharing()) { SharedObject::InitSharedClassProperties(); } $oProfileSet = new DBObjectSet(DBObjectSearch::FromOQL_AllData("SELECT URP_Profiles")); $this->m_aProfiles = array(); while ($oProfile = $oProfileSet->Fetch()) { $this->m_aProfiles[$oProfile->GetKey()] = $oProfile; } $oKPI->ComputeAndReport('Load of user management cache (excepted Action Grants)'); /* echo "<pre>\n"; print_r($this->m_aProfiles); print_r($this->m_aUserProfiles); print_r($this->m_aUserOrgs); echo "</pre>\n"; exit; */ return true; }
public function ToArgs($sArgName = 'this') { if (is_null($this->m_aAsArgs)) { $oKPI = new ExecutionKPI(); $aScalarArgs = $this->ToArgsForQuery($sArgName); $aScalarArgs[$sArgName] = $this->GetKey(); $aScalarArgs[$sArgName . '->id'] = $this->GetKey(); $aScalarArgs[$sArgName . '->hyperlink()'] = $this->GetHyperlink('iTopStandardURLMaker', false); $aScalarArgs[$sArgName . '->hyperlink(portal)'] = $this->GetHyperlink('PortalURLMaker', false); $aScalarArgs[$sArgName . '->name()'] = $this->GetName(); $sClass = get_class($this); foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) { if ($oAttDef instanceof AttributeCaseLog) { $oCaseLog = $this->Get($sAttCode); $aScalarArgs[$sArgName . '->' . $sAttCode] = $oCaseLog->GetText(); $sHead = $oCaseLog->GetLatestEntry(); $aScalarArgs[$sArgName . '->head(' . $sAttCode . ')'] = $sHead; $aScalarArgs[$sArgName . '->head_html(' . $sAttCode . ')'] = '<div class="caselog_entry">' . str_replace(array("\r\n", "\n", "\r"), "<br/>", htmlentities($sHead, ENT_QUOTES, 'UTF-8')) . '</div>'; $aScalarArgs[$sArgName . '->html(' . $sAttCode . ')'] = $oCaseLog->GetAsEmailHtml(); } elseif ($oAttDef->IsScalar()) { $aScalarArgs[$sArgName . '->' . $sAttCode] = $this->Get($sAttCode); // #@# Note: This has been proven to be quite slow, this can slow down bulk load $sAsHtml = $this->GetAsHtml($sAttCode); $aScalarArgs[$sArgName . '->html(' . $sAttCode . ')'] = $sAsHtml; $aScalarArgs[$sArgName . '->label(' . $sAttCode . ')'] = $this->GetEditValue($sAttCode); // "Nice" display value, but without HTML tags and entities } elseif ($oAttDef->IsLinkSet()) { $sRemoteName = $oAttDef->IsIndirect() ? $oAttDef->GetExtKeyToRemote() . '_friendlyname' : 'friendlyname'; $oLinkSet = clone $this->Get($sAttCode); // Workaround/Safety net for Trac #887 $iLimit = MetaModel::GetConfig()->Get('max_linkset_output'); if ($iLimit > 0) { $oLinkSet->SetLimit($iLimit); } $aNames = $oLinkSet->GetColumnAsArray($sRemoteName); if ($iLimit > 0) { $iTotal = $oLinkSet->Count(); if ($iTotal > count($aNames)) { $aNames[] = '... ' . Dict::Format('UI:TruncatedResults', count($aNames), $iTotal); } } $sNames = implode("\n", $aNames); $aScalarArgs[$sArgName . '->' . $sAttCode] = $sNames; $aScalarArgs[$sArgName . '->html(' . $sAttCode . ')'] = '<ul><li>' . implode("</li><li>", $aNames) . '</li></ul>'; } } $this->m_aAsArgs = $aScalarArgs; $oKPI->ComputeStats('ToArgs', get_class($this)); } return $this->m_aAsArgs; }
public static function LoadConfig($oConfiguration, $bAllowCache = false) { self::$m_oConfig = $oConfiguration; // Set log ASAP if (self::$m_oConfig->GetLogGlobal()) { if (self::$m_oConfig->GetLogIssue()) { self::$m_bLogIssue = true; IssueLog::Enable(APPROOT . 'log/error.log'); } self::$m_bLogNotification = self::$m_oConfig->GetLogNotification(); self::$m_bLogWebService = self::$m_oConfig->GetLogWebService(); ToolsLog::Enable(APPROOT . 'log/tools.log'); } else { self::$m_bLogIssue = false; self::$m_bLogNotification = false; self::$m_bLogWebService = false; } ExecutionKPI::EnableDuration(self::$m_oConfig->Get('log_kpi_duration')); ExecutionKPI::EnableMemory(self::$m_oConfig->Get('log_kpi_memory')); ExecutionKPI::SetAllowedUser(self::$m_oConfig->Get('log_kpi_user_id')); self::$m_bSkipCheckToWrite = self::$m_oConfig->Get('skip_check_to_write'); self::$m_bSkipCheckExtKeys = self::$m_oConfig->Get('skip_check_ext_keys'); self::$m_bUseAPCCache = $bAllowCache && self::$m_oConfig->Get('apc_cache.enabled') && function_exists('apc_fetch') && function_exists('apc_store'); DBSearch::EnableQueryCache(self::$m_oConfig->GetQueryCacheEnabled(), self::$m_bUseAPCCache, self::$m_oConfig->Get('apc_cache.query_ttl')); DBSearch::EnableQueryTrace(self::$m_oConfig->GetLogQueries()); DBSearch::EnableQueryIndentation(self::$m_oConfig->Get('query_indentation_enabled')); DBSearch::EnableOptimizeQuery(self::$m_oConfig->Get('query_optimization_enabled')); // PHP timezone first... // $sPHPTimezone = self::$m_oConfig->Get('timezone'); if ($sPHPTimezone == '') { // Leave as is... up to the admin to set a value somewhere... //$sPHPTimezone = date_default_timezone_get(); } else { date_default_timezone_set($sPHPTimezone); } // Note: load the dictionary as soon as possible, because it might be // needed when some error occur $sAppIdentity = 'itop-' . MetaModel::GetEnvironmentId(); $bDictInitializedFromData = false; if (!self::$m_bUseAPCCache || !Dict::InCache($sAppIdentity)) { $bDictInitializedFromData = true; foreach (self::$m_oConfig->GetDictionaries() as $sModule => $sToInclude) { self::IncludeModule('dictionaries', $sToInclude); } } // Set the language... after the dictionaries have been loaded! Dict::SetDefaultLanguage(self::$m_oConfig->GetDefaultLanguage()); // Romain: this is the only way I've found to cope with the fact that // classes have to be derived from cmdbabstract (to be editable in the UI) require_once APPROOT . '/application/cmdbabstract.class.inc.php'; foreach (self::$m_oConfig->GetAppModules() as $sModule => $sToInclude) { self::IncludeModule('application', $sToInclude); } foreach (self::$m_oConfig->GetDataModels() as $sModule => $sToInclude) { self::IncludeModule('business', $sToInclude); } foreach (self::$m_oConfig->GetWebServiceCategories() as $sModule => $sToInclude) { self::IncludeModule('webservice', $sToInclude); } foreach (self::$m_oConfig->GetAddons() as $sModule => $sToInclude) { self::IncludeModule('addons', $sToInclude); } $sServer = self::$m_oConfig->GetDBHost(); $sUser = self::$m_oConfig->GetDBUser(); $sPwd = self::$m_oConfig->GetDBPwd(); $sSource = self::$m_oConfig->GetDBName(); $sTablePrefix = self::$m_oConfig->GetDBSubname(); $sCharacterSet = self::$m_oConfig->GetDBCharacterSet(); $sCollation = self::$m_oConfig->GetDBCollation(); if (self::$m_bUseAPCCache) { $oKPI = new ExecutionKPI(); // Note: For versions of APC older than 3.0.17, fetch() accepts only one parameter // $sOqlAPCCacheId = 'itop-' . MetaModel::GetEnvironmentId() . '-metamodel'; $result = apc_fetch($sOqlAPCCacheId); if (is_array($result)) { // todo - verifier que toutes les classes mentionnees ici sont chargees dans InitClasses() self::$m_aExtensionClasses = $result['m_aExtensionClasses']; self::$m_Category2Class = $result['m_Category2Class']; self::$m_aRootClasses = $result['m_aRootClasses']; self::$m_aParentClasses = $result['m_aParentClasses']; self::$m_aChildClasses = $result['m_aChildClasses']; self::$m_aClassParams = $result['m_aClassParams']; self::$m_aAttribDefs = $result['m_aAttribDefs']; self::$m_aAttribOrigins = $result['m_aAttribOrigins']; self::$m_aExtKeyFriends = $result['m_aExtKeyFriends']; self::$m_aIgnoredAttributes = $result['m_aIgnoredAttributes']; self::$m_aFilterDefs = $result['m_aFilterDefs']; self::$m_aFilterOrigins = $result['m_aFilterOrigins']; self::$m_aListInfos = $result['m_aListInfos']; self::$m_aListData = $result['m_aListData']; self::$m_aRelationInfos = $result['m_aRelationInfos']; self::$m_aStates = $result['m_aStates']; self::$m_aStimuli = $result['m_aStimuli']; self::$m_aTransitions = $result['m_aTransitions']; self::$m_aHighlightScales = $result['m_aHighlightScales']; } $oKPI->ComputeAndReport('Metamodel APC (fetch + read)'); } if (count(self::$m_aAttribDefs) == 0) { // The includes have been included, let's browse the existing classes and // develop some data based on the proposed model $oKPI = new ExecutionKPI(); self::InitClasses($sTablePrefix); $oKPI->ComputeAndReport('Initialization of Data model structures'); if (self::$m_bUseAPCCache) { $oKPI = new ExecutionKPI(); $aCache = array(); $aCache['m_aExtensionClasses'] = self::$m_aExtensionClasses; $aCache['m_Category2Class'] = self::$m_Category2Class; $aCache['m_aRootClasses'] = self::$m_aRootClasses; // array of "classname" => "rootclass" $aCache['m_aParentClasses'] = self::$m_aParentClasses; // array of ("classname" => array of "parentclass") $aCache['m_aChildClasses'] = self::$m_aChildClasses; // array of ("classname" => array of "childclass") $aCache['m_aClassParams'] = self::$m_aClassParams; // array of ("classname" => array of class information) $aCache['m_aAttribDefs'] = self::$m_aAttribDefs; // array of ("classname" => array of attributes) $aCache['m_aAttribOrigins'] = self::$m_aAttribOrigins; // array of ("classname" => array of ("attcode"=>"sourceclass")) $aCache['m_aExtKeyFriends'] = self::$m_aExtKeyFriends; // array of ("classname" => array of ("indirect ext key attcode"=> array of ("relative ext field"))) $aCache['m_aIgnoredAttributes'] = self::$m_aIgnoredAttributes; //array of ("classname" => array of ("attcode") $aCache['m_aFilterDefs'] = self::$m_aFilterDefs; // array of ("classname" => array filterdef) $aCache['m_aFilterOrigins'] = self::$m_aFilterOrigins; // array of ("classname" => array of ("attcode"=>"sourceclass")) $aCache['m_aListInfos'] = self::$m_aListInfos; // array of ("listcode" => various info on the list, common to every classes) $aCache['m_aListData'] = self::$m_aListData; // array of ("classname" => array of "listcode" => list) $aCache['m_aRelationInfos'] = self::$m_aRelationInfos; // array of ("relcode" => various info on the list, common to every classes) $aCache['m_aStates'] = self::$m_aStates; // array of ("classname" => array of "statecode"=>array('label'=>..., attribute_inherit=> attribute_list=>...)) $aCache['m_aStimuli'] = self::$m_aStimuli; // array of ("classname" => array of ("stimuluscode"=>array('label'=>...))) $aCache['m_aTransitions'] = self::$m_aTransitions; // array of ("classname" => array of ("statcode_from"=>array of ("stimuluscode" => array('target_state'=>..., 'actions'=>array of handlers procs, 'user_restriction'=>TBD))) $aCache['m_aHighlightScales'] = self::$m_aHighlightScales; // array of ("classname" => array of higlightcodes))) apc_store($sOqlAPCCacheId, $aCache); $oKPI->ComputeAndReport('Metamodel APC (store)'); } } if (self::$m_bUseAPCCache && $bDictInitializedFromData) { Dict::InitCache($sAppIdentity); } self::$m_sDBName = $sSource; self::$m_sTablePrefix = $sTablePrefix; CMDBSource::Init($sServer, $sUser, $sPwd); // do not select the DB (could not exist) CMDBSource::SetCharacterSet($sCharacterSet, $sCollation); // Later when timezone implementation is correctly done: CMDBSource::SetTimezone($sDBTimezone); }
function DoShowGrantSumary($oPage, $sClassCategory) { if (UserRights::IsAdministrator($this)) { // Looks dirty, but ok that's THE ONE $oPage->p(Dict::S('UI:UserManagement:AdminProfile+')); return; } $oKPI = new ExecutionKPI(); $aDisplayData = array(); foreach (MetaModel::GetClasses($sClassCategory) as $sClass) { $aClassStimuli = MetaModel::EnumStimuli($sClass); if (count($aClassStimuli) > 0) { $aStimuli = array(); foreach ($aClassStimuli as $sStimulusCode => $oStimulus) { if (UserRights::IsStimulusAllowed($sClass, $sStimulusCode, null, $this)) { $aStimuli[] = '<span title="' . $sStimulusCode . ': ' . htmlentities($oStimulus->GetDescription(), ENT_QUOTES, 'UTF-8') . '">' . htmlentities($oStimulus->GetLabel(), ENT_QUOTES, 'UTF-8') . '</span>'; } } $sStimuli = implode(', ', $aStimuli); } else { $sStimuli = '<em title="' . Dict::S('UI:UserManagement:NoLifeCycleApplicable+') . '">' . Dict::S('UI:UserManagement:NoLifeCycleApplicable') . '</em>'; } $aDisplayData[] = array('class' => MetaModel::GetName($sClass), 'read' => $this->GetGrantAsHtml($sClass, UR_ACTION_READ), 'bulkread' => $this->GetGrantAsHtml($sClass, UR_ACTION_BULK_READ), 'write' => $this->GetGrantAsHtml($sClass, UR_ACTION_MODIFY), 'bulkwrite' => $this->GetGrantAsHtml($sClass, UR_ACTION_BULK_MODIFY), 'stimuli' => $sStimuli); } $oKPI->ComputeAndReport('Computation of user rights'); $aDisplayConfig = array(); $aDisplayConfig['class'] = array('label' => Dict::S('UI:UserManagement:Class'), 'description' => Dict::S('UI:UserManagement:Class+')); $aDisplayConfig['read'] = array('label' => Dict::S('UI:UserManagement:Action:Read'), 'description' => Dict::S('UI:UserManagement:Action:Read+')); $aDisplayConfig['bulkread'] = array('label' => Dict::S('UI:UserManagement:Action:BulkRead'), 'description' => Dict::S('UI:UserManagement:Action:BulkRead+')); $aDisplayConfig['write'] = array('label' => Dict::S('UI:UserManagement:Action:Modify'), 'description' => Dict::S('UI:UserManagement:Action:Modify+')); $aDisplayConfig['bulkwrite'] = array('label' => Dict::S('UI:UserManagement:Action:BulkModify'), 'description' => Dict::S('UI:UserManagement:Action:BulkModify+')); $aDisplayConfig['stimuli'] = array('label' => Dict::S('UI:UserManagement:Action:Stimuli'), 'description' => Dict::S('UI:UserManagement:Action:Stimuli+')); $oPage->table($aDisplayConfig, $aDisplayData); }
/** * Outputs (via some echo) the complete HTML page by assembling all its elements */ public function output() { foreach ($this->a_headers as $s_header) { header($s_header); } $s_captured_output = $this->ob_get_clean_safe(); echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"; echo "<html>\n"; echo "<head>\n"; echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"; echo "<title>" . htmlentities($this->s_title, ENT_QUOTES, 'UTF-8') . "</title>\n"; echo $this->get_base_tag(); foreach ($this->a_linked_scripts as $s_script) { // Make sure that the URL to the script contains the application's version number // so that the new script do NOT get reloaded from the cache when the application is upgraded if (strpos($s_script, '?') === false) { $s_script .= "?itopversion=" . ITOP_VERSION; } else { $s_script .= "&itopversion=" . ITOP_VERSION; } echo "<script type=\"text/javascript\" src=\"{$s_script}\"></script>\n"; } if (count($this->a_scripts) > 0) { echo "<script type=\"text/javascript\">\n"; foreach ($this->a_scripts as $s_script) { echo "{$s_script}\n"; } echo "</script>\n"; } $this->output_dict_entries(); foreach ($this->a_linked_stylesheets as $a_stylesheet) { if ($a_stylesheet['condition'] != "") { echo "<!--[if {$a_stylesheet['condition']}]>\n"; } echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$a_stylesheet['link']}\" />\n"; if ($a_stylesheet['condition'] != "") { echo "<![endif]-->\n"; } } if (count($this->a_styles) > 0) { echo "<style>\n"; foreach ($this->a_styles as $s_style) { echo "{$s_style}\n"; } echo "</style>\n"; } if (class_exists('MetaModel') && MetaModel::GetConfig()) { echo "<link rel=\"shortcut icon\" href=\"" . utils::GetAbsoluteUrlAppRoot() . "images/favicon.ico\" />\n"; } echo "</head>\n"; echo "<body>\n"; echo self::FilterXSS($this->s_content); if (trim($s_captured_output) != "") { echo "<div class=\"raw_output\">" . self::FilterXSS($s_captured_output) . "</div>\n"; } echo '<div id="at_the_end">' . self::FilterXSS($this->s_deferred_content) . '</div>'; echo "</body>\n"; echo "</html>\n"; if (class_exists('DBSearch')) { DBSearch::RecordQueryTrace(); } if (class_exists('ExecutionKPI')) { ExecutionKPI::ReportStats(); } }
$aForm[] = array('label' => "CIs for the big ticket:", 'input' => "<input id=\"to\" type=\"text\" name=\"plannedbigticketcis\" value=\"200\">", 'help' => 'Number of CI for the single big ticket'); $oP->form($aForm); $oP->add("</fieldset>\n"); $oP->add("<input type=\"hidden\" name=\"operation\" value=\"create_tickets\">\n"); $oP->add("<button type=\"submit\">Next >></button>\n"); $oP->add("</form>\n"); } /** * Main program */ LoginWebPage::DoLogin(); // Check user rights and prompt if needed $sOperation = Utils::ReadParam('operation', 'step1'); $oP = new SetupPage('iTop benchmark utility'); ExecutionKPI::EnableDuration(); $oKPI = new ExecutionKPI(); try { switch ($sOperation) { case 'step1': DisplayStep1($oP); break; case 'create_structure': $oP->no_cache(); $iPlannedContacts = Utils::ReadParam('plannedcontacts'); $iPlannedContracts = Utils::ReadParam('plannedcontracts'); $oDataCreation = new BenchmarkDataCreation(); $oDataCreation->PlanStructure($iPlannedContacts, $iPlannedContracts); $oDataCreation->ShowPlans($oP); $oDataCreation->ShowForm($oP, 'create_structure_go'); break; case 'create_structure_go':
public final function CheckToWrite() { if (MetaModel::SkipCheckToWrite()) { return array(true, array()); } if (is_null($this->m_bCheckStatus)) { $this->m_aCheckIssues = array(); $oKPI = new ExecutionKPI(); $this->DoCheckToWrite(); $oKPI->ComputeStats('CheckToWrite', get_class($this)); if (count($this->m_aCheckIssues) == 0) { $this->m_bCheckStatus = true; } else { $this->m_bCheckStatus = false; } } return array($this->m_bCheckStatus, $this->m_aCheckIssues, $this->m_bSecurityIssue); }
public static function QueryToArray($sSql) { $aData = array(); $oKPI = new ExecutionKPI(); try { $oResult = self::$m_oMysqli->query($sSql); } catch (mysqli_sql_exception $e) { $oKPI->ComputeStats('Query exec (mySQL)', $sSql); MySQLException('Failed to issue SQL query', array('query' => $sSql, $e)); } $oKPI->ComputeStats('Query exec (mySQL)', $sSql); if ($oResult === false) { throw new MySQLException('Failed to issue SQL query', array('query' => $sSql)); } while ($aRow = $oResult->fetch_array(MYSQLI_BOTH)) { $aData[] = $aRow; } $oResult->free(); return $aData; }
} /*********************************************************************************** * * Main user interface page, starts here * * ***********************************************************************************/ try { require_once '../approot.inc.php'; require_once APPROOT . '/application/application.inc.php'; require_once APPROOT . '/application/itopwebpage.class.inc.php'; require_once APPROOT . '/application/wizardhelper.class.inc.php'; require_once APPROOT . '/application/startup.inc.php'; $operation = utils::ReadParam('operation', ''); $oKPI = new ExecutionKPI(); $oKPI->ComputeAndReport('Data model loaded'); $oKPI = new ExecutionKPI(); require_once APPROOT . '/application/loginwebpage.class.inc.php'; $sLoginMessage = LoginWebPage::DoLogin(); // Check user rights and prompt if needed $oAppContext = new ApplicationContext(); $oKPI->ComputeAndReport('User login'); $oP = new iTopWebPage(Dict::S('UI:WelcomeToITop')); $oP->SetMessage($sLoginMessage); // All the following actions use advanced forms that require more javascript to be loaded switch ($operation) { case 'new': // Form to create a new object // Form to create a new object case 'modify': // Form to modify an object // Form to modify an object