function buscaNomina($rfc_Cliente, $rfc_Pagadora, $path, $params) { $caso = new DBSearch(); $app_uid = $caso->buscarCaso($rfc_Cliente, $rfc_Pagadora); if ($app_uid) { /* *The subeArchivo method upload the file to processmaker */ /********SUBE ARCHIVO SGN******/ $subido = $this->subeArchivo($app_uid, $path); /* *The login method is a processmaker web service */ /********LOGIN WS PROCESSMAKER******/ $sessionId = $this->login(); /* *The insertar_SGN method save the info inside data tables */ /********ALMACENA INFO DE ARCHIVO SGN******/ $insertado = $caso->insertar_SGN($app_uid, $params); $continuado = $this->continuarCaso($app_uid, $sessionId); if (!$continuado) { return "Error al continuar caso"; } $caso->actualizarCaso($app_uid); return $app_uid . " " . $sessionId . $insertado . $subido; } else { return "No se encontro caso"; } }
/** * Adds the context parameters to the audit query */ function FilterByContext(DBSearch &$oFilter, ApplicationContext $oAppContext) { $sObjClass = $oFilter->GetClass(); $aContextParams = $oAppContext->GetNames(); $aCallSpec = array($sObjClass, 'MapContextParam'); if (is_callable($aCallSpec)) { foreach ($aContextParams as $sParamName) { $sValue = $oAppContext->GetCurrentValue($sParamName, 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)) { // Check if the condition points to a hierarchical key if ($sAttCode == 'id') { // Filtering on the objects themselves $sHierarchicalKeyCode = MetaModel::IsHierarchicalClass($sObjClass); 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 { $oAttDef = MetaModel::GetAttributeDef($sObjClass, $sAttCode); $bConditionAdded = false; if ($oAttDef->IsExternalKey()) { $sHierarchicalKeyCode = MetaModel::IsHierarchicalClass($oAttDef->GetTargetClass()); if ($sHierarchicalKeyCode !== false) { $oRootFilter = new DBObjectSearch($oAttDef->GetTargetClass()); $oRootFilter->AddCondition('id', $sValue); $oHKFilter = new DBObjectSearch($oAttDef->GetTargetClass()); $oHKFilter->AddCondition_PointingTo($oRootFilter, $sHierarchicalKeyCode, TREE_OPERATOR_BELOW); // Use the 'below' operator by default $oFilter->AddCondition_PointingTo($oHKFilter, $sAttCode); $bConditionAdded = true; } } } if (!$bConditionAdded) { $oFilter->AddCondition($sAttCode, $sValue); } } } } } }
public function output() { if (class_exists('DBSearch')) { DBSearch::RecordQueryTrace(); } if (class_exists('ExecutionKPI')) { ExecutionKPI::ReportStats(); } }
/** * Create a new set based on a Search definition. * * @param DBSearch $oFilter The search filter defining the objects which are part of the set (multiple columns/objects per row are supported) * @param hash $aOrderBy Array of '[<classalias>.]attcode' => bAscending * @param hash $aArgs Values to substitute for the search/query parameters (if any). Format: param_name => value * @param hash $aExtendedDataSpec * @param int $iLimitCount Maximum number of rows to load (i.e. equivalent to MySQL's LIMIT start, count) * @param int $iLimitStart Index of the first row to load (i.e. equivalent to MySQL's LIMIT start, count) */ public function __construct(DBSearch $oFilter, $aOrderBy = array(), $aArgs = array(), $aExtendedDataSpec = null, $iLimitCount = 0, $iLimitStart = 0) { $this->m_oFilter = $oFilter->DeepClone(); $this->m_aAddedIds = array(); $this->m_aOrderBy = $aOrderBy; $this->m_aArgs = $aArgs; $this->m_aAttToLoad = null; $this->m_aExtendedDataSpec = $aExtendedDataSpec; $this->m_iLimitCount = $iLimitCount; $this->m_iLimitStart = $iLimitStart; $this->m_iNumTotalDBRows = null; // Total number of rows for the query without LIMIT. null if unknown yet $this->m_iNumLoadedDBRows = 0; // Total number of rows LOADED in $this->m_oSQLResult via a SQL query. 0 by default $this->m_bLoaded = false; // true when the filter has been used OR the set is built step by step (AddObject...) $this->m_aAddedObjects = array(); // array of (row => array of (classalias) => object/null) storing the objects added "in memory" $this->m_iCurrRow = 0; $this->m_oSQLResult = null; }
public function output() { if (!$this->m_bPassThrough) { // Get the unexpected output but do nothing with it $sTrash = $this->ob_get_clean_safe(); $this->s_content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?" . ">\n" . trim($this->s_content); $this->add_header("Content-Length: " . strlen($this->s_content)); foreach ($this->a_headers as $s_header) { header($s_header); } echo $this->s_content; } if (class_exists('DBSearch')) { DBSearch::RecordQueryTrace(); } }
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(); } }
protected static function search_and_show_list(DBSearch $oMyFilter) { $oObjSet = new CMDBObjectSet($oMyFilter); echo $oMyFilter->ToOQL() . "' - Found " . $oObjSet->Count() . " items.</br>\n"; self::show_list($oObjSet); }
/** * Constructs a DisplayBlock object from an XML template * @param $sTemplate string The XML template * @return DisplayBlock The DisplayBlock object, or null if the template is invalid */ public static function FromTemplate($sTemplate) { $iStartPos = stripos($sTemplate, '<' . self::TAG_BLOCK . ' ', 0); $iEndPos = stripos($sTemplate, '</' . self::TAG_BLOCK . '>', $iStartPos); $iEndTag = stripos($sTemplate, '>', $iStartPos); $aParams = array(); if ($iStartPos === false || $iEndPos === false) { return null; } // invalid template $sITopBlock = substr($sTemplate, $iStartPos, $iEndPos - $iStartPos + strlen('</' . self::TAG_BLOCK . '>')); $sITopData = substr($sTemplate, 1 + $iEndTag, $iEndPos - $iEndTag - 1); $sITopTag = substr($sTemplate, $iStartPos + strlen('<' . self::TAG_BLOCK), $iEndTag - $iStartPos - strlen('<' . self::TAG_BLOCK)); $aMatches = array(); $sBlockClass = "DisplayBlock"; $bAsynchronous = false; $sBlockType = 'list'; $sEncoding = 'text/serialize'; if (preg_match('/ type="(.*)"/U', $sITopTag, $aMatches)) { $sBlockType = strtolower($aMatches[1]); } if (preg_match('/ asynchronous="(.*)"/U', $sITopTag, $aMatches)) { $bAsynchronous = strtolower($aMatches[1]) == 'true'; } if (preg_match('/ blockclass="(.*)"/U', $sITopTag, $aMatches)) { $sBlockClass = $aMatches[1]; } if (preg_match('/ objectclass="(.*)"/U', $sITopTag, $aMatches)) { $sObjectClass = $aMatches[1]; } if (preg_match('/ encoding="(.*)"/U', $sITopTag, $aMatches)) { $sEncoding = strtolower($aMatches[1]); } if (preg_match('/ link_attr="(.*)"/U', $sITopTag, $aMatches)) { // The list to display is a list of links to the specified object $aParams['link_attr'] = $aMatches[1]; // Name of the Ext. Key that makes this linkage } if (preg_match('/ target_attr="(.*)"/U', $sITopTag, $aMatches)) { // The list to display is a list of links to the specified object $aParams['target_attr'] = $aMatches[1]; // Name of the Ext. Key that make this linkage } if (preg_match('/ object_id="(.*)"/U', $sITopTag, $aMatches)) { // The list to display is a list of links to the specified object $aParams['object_id'] = $aMatches[1]; // Id of the object to be linked to } // Parameters contains a list of extra parameters for the block // the syntax is param_name1:value1;param_name2:value2;... if (preg_match('/ parameters="(.*)"/U', $sITopTag, $aMatches)) { $sParameters = $aMatches[1]; $aPairs = explode(';', $sParameters); foreach ($aPairs as $sPair) { if (preg_match('/(.*)\\:(.*)/', $sPair, $aMatches)) { $aParams[trim($aMatches[1])] = trim($aMatches[2]); } } } if (!empty($aParams['link_attr'])) { // Check that all mandatory parameters are present: if (empty($aParams['object_id'])) { // if 'links' mode is requested the d of the object to link to must be specified throw new ApplicationException(Dict::S('UI:Error:MandatoryTemplateParameter_object_id')); } if (empty($aParams['target_attr'])) { // if 'links' mode is requested the id of the object to link to must be specified throw new ApplicationException(Dict::S('UI:Error:MandatoryTemplateParameter_target_attr')); } } switch ($sEncoding) { case 'text/serialize': $oFilter = DBSearch::unserialize($sITopData); break; case 'text/oql': $oFilter = DBSearch::FromOQL($sITopData); break; } return new $sBlockClass($oFilter, $sBlockType, $bAsynchronous, $aParams); }
/** * 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(); }
public static function EnableOptimizeQuery($bEnabled) { self::$m_bOptimizeQueries = $bEnabled; }
function DisplayBareRelations(WebPage $oPage, $bEditMode = false) { parent::DisplayBareRelations($oPage, $bEditMode); $sTicketListAttCode = 'tickets_list'; if (MetaModel::IsValidAttCode(get_class($this), $sTicketListAttCode)) { // Display one list per leaf class (the only way to display the status as of now) $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sTicketListAttCode); $sLnkClass = $oAttDef->GetLinkedClass(); $sExtKeyToMe = $oAttDef->GetExtKeyToMe(); $sExtKeyToRemote = $oAttDef->GetExtKeyToRemote(); $iTotal = 0; $aSearches = array(); foreach (MetaModel::EnumChildClasses('Ticket') as $sSubClass) { if (!MetaModel::HasChildrenClasses($sSubClass)) { $sStateAttCode = MetaModel::GetStateAttributeCode($sSubClass); if ($sStateAttCode != '') { $oSearch = DBSearch::FromOQL("SELECT {$sSubClass} AS t JOIN {$sLnkClass} AS lnk ON lnk.{$sExtKeyToRemote} = t.id WHERE {$sExtKeyToMe} = :myself AND {$sStateAttCode} NOT IN ('rejected', 'resolved', 'closed')", array('myself' => $this->GetKey())); $aSearches[$sSubClass] = $oSearch; $oSet = new DBObjectSet($oSearch); $iTotal += $oSet->Count(); } } } $sCount = $iTotal > 0 ? ' (' . $iTotal . ')' : ''; $oPage->SetCurrentTab(Dict::S('Class:FunctionalCI/Tab:OpenedTickets') . $sCount); foreach ($aSearches as $sSubClass => $oSearch) { $sBlockId = __CLASS__ . '_opened_' . $sSubClass; $oPage->add('<fieldset>'); $oPage->add('<legend>' . MetaModel::GetName($sSubClass) . '</legend>'); $oBlock = new DisplayBlock($oSearch, 'list', false); $oBlock->Display($oPage, $sBlockId, array('menu' => false)); $oPage->add('</fieldset>'); } } }
$oPage->add('</textarea>'); $oPage->add("</div>"); $oPage->add("</div>"); break; case 'history': $oPage->SetContentType('text/html'); $id = (int) utils::ReadParam('id', 0); $iStart = (int) utils::ReadParam('start', 0); $iCount = (int) utils::ReadParam('count', MetaModel::GetConfig()->Get('max_history_length', '50')); $oObj = MetaModel::GetObject($sClass, $id); $oObj->DisplayBareHistory($oPage, false, $iCount, $iStart); $oPage->add_ready_script("\$('#history table.listResults').tableHover(); \$('#history table.listResults').tablesorter( { widgets: ['myZebra', 'truncatedList']} );"); break; case 'history_from_filter': $oPage->SetContentType('text/html'); $oHistoryFilter = DBSearch::unserialize($sFilter); $iStart = (int) utils::ReadParam('start', 0); $iCount = (int) utils::ReadParam('count', MetaModel::GetConfig()->Get('max_history_length', '50')); $oBlock = new HistoryBlock($oHistoryFilter, 'table', false); $oBlock->SetLimit($iCount, $iStart); $oBlock->Display($oPage, 'history'); $oPage->add_ready_script("\$('#history table.listResults').tableHover(); \$('#history table.listResults').tablesorter( { widgets: ['myZebra', 'truncatedList']} );"); break; case 'full_text_search': $aFullTextNeedles = utils::ReadParam('needles', array(), false, 'raw_data'); $sFullText = trim(implode(' ', $aFullTextNeedles)); $sClassName = utils::ReadParam('class', ''); $iCount = utils::ReadParam('count', 0); $iCurrentPos = utils::ReadParam('position', 0); $iTune = utils::ReadParam('tune', 0); if (empty($sFullText)) {
public function Intersect(DBSearch $oFilter) { if ($oFilter instanceof DBUnionSearch) { // Develop! $aFilters = $oFilter->GetSearches(); } else { $aFilters = array($oFilter); } $aSearches = array(); foreach ($aFilters as $oRightFilter) { $oLeftFilter = $this->DeepClone(); $oRightFilter = $oRightFilter->DeepClone(); if ($oLeftFilter->GetClass() != $oRightFilter->GetClass()) { if (MetaModel::IsParentClass($oLeftFilter->GetClass(), $oRightFilter->GetClass())) { // Specialize $oLeftFilter $oLeftFilter->ChangeClass($oRightFilter->GetClass()); } elseif (MetaModel::IsParentClass($oRightFilter->GetClass(), $oLeftFilter->GetClass())) { // Specialize $oRightFilter $oRightFilter->ChangeClass($oLeftFilter->GetClass()); } else { throw new CoreException("Attempting to merge a filter of class '{$oLeftFilter->GetClass()}' with a filter of class '{$oRightFilter->GetClass()}'"); } } $aAliasTranslation = array(); $oLeftFilter->MergeWith_InNamespace($oRightFilter, $oLeftFilter->m_aClasses, $aAliasTranslation); $oLeftFilter->TransferConditionExpression($oRightFilter, $aAliasTranslation); $aSearches[] = $oLeftFilter; } if (count($aSearches) == 1) { // return a DBObjectSearch return $aSearches[0]; } else { return new DBUnionSearch($aSearches); } }
/** * Initializes the default search parameters based on 1) a 'current' object and 2) the silos defined by the context * @param DBObject $oSourceObj * @param DBSearch $oSearch */ protected function SetSearchDefaultFromContext($oSourceObj, &$oSearch) { $oAppContext = new ApplicationContext(); $sSrcClass = get_class($oSourceObj); $sDestClass = $oSearch->GetClass(); foreach ($oAppContext->GetNames() as $key) { // Find the value of the object corresponding to each 'context' parameter $aCallSpec = array($sSrcClass, 'MapContextParam'); $sAttCode = ''; if (is_callable($aCallSpec)) { $sAttCode = call_user_func($aCallSpec, $key); // Returns null when there is no mapping for this parameter } if (MetaModel::IsValidAttCode($sSrcClass, $sAttCode)) { $oAttDef = MetaModel::GetAttributeDef($sSrcClass, $sAttCode); $defaultValue = $oSourceObj->Get($sAttCode); // Find the attcode for the same 'context' parameter in the destination class // and sets its value as the default value for the search condition $aCallSpec = array($sDestClass, 'MapContextParam'); $sAttCode = ''; if (is_callable($aCallSpec)) { $sAttCode = call_user_func($aCallSpec, $key); // Returns null when there is no mapping for this parameter } if (MetaModel::IsValidAttCode($sDestClass, $sAttCode) && !empty($defaultValue)) { $oSearch->AddCondition($sAttCode, $defaultValue); } } } }
/** * Echoes the content of the whole page * @return void */ public function output() { if (!empty($this->sContentType)) { $this->add_header('Content-type: ' . $this->sContentType); } if (!empty($this->sContentDisposition)) { $this->add_header('Content-Disposition: ' . $this->sContentDisposition . '; filename="' . $this->sContentFileName . '"'); } foreach ($this->a_headers as $s_header) { header($s_header); } if ($this->m_oTabs->TabsContainerCount() > 0) { $this->add_ready_script(<<<EOF \t\t\t// The "tab widgets" to handle. \t\t\tvar tabs = \$('div[id^=tabbedContent]'); \t\t\t \t\t\t// Ugly patch for a change in the behavior of jQuery UI: \t\t\t// Before jQuery UI 1.9, tabs were always considered as "local" (opposed to Ajax) \t\t\t// when their href was beginning by #. Starting with 1.9, a <base> tag in the page \t\t\t// is taken into account and causes "local" tabs to be considered as Ajax \t\t\t// unless their URL is equal to the URL of the page... \t\t\tif (\$('base').length > 0) \t\t\t{ \t\t\t\t\$('div[id^=tabbedContent] > ul > li > a').each(function() { \t\t\t\t\tvar sHash = location.hash; \t\t\t\t\tvar sCleanLocation = location.href.toString().replace(sHash, '').replace(/#\$/, ''); \t\t \t\t\$(this).attr("href", sCleanLocation+\$(this).attr("href")); \t\t\t\t}); \t\t\t} \t\t\tif (\$.bbq) \t\t\t{ \t\t\t\t// This selector will be reused when selecting actual tab widget A elements. \t\t\t\tvar tab_a_selector = 'ul.ui-tabs-nav a'; \t\t\t\t \t\t\t\t// Enable tabs on all tab widgets. The `event` property must be overridden so \t\t\t\t// that the tabs aren't changed on click, and any custom event name can be \t\t\t\t// specified. Note that if you define a callback for the 'select' event, it \t\t\t\t// will be executed for the selected tab whenever the hash changes. \t\t\t\ttabs.tabs({ event: 'change' }); \t\t\t\t \t\t\t\t// Define our own click handler for the tabs, overriding the default. \t\t\t\ttabs.find( tab_a_selector ).click(function() \t\t\t\t{ \t\t\t\t\tvar state = {}; \t\t\t\t\t\t\t \t\t\t\t\t// Get the id of this tab widget. \t\t\t\t\tvar id = \$(this).closest( 'div[id^=tabbedContent]' ).attr( 'id' ); \t\t\t\t\t \t\t\t\t\t// Get the index of this tab. \t\t\t\t\tvar idx = \$(this).parent().prevAll().length; \t\t\t\t\t \t\t\t\t\t// Set the state! \t\t\t\t\tstate[ id ] = idx; \t\t\t\t\t\$.bbq.pushState( state ); \t\t\t\t}); \t\t\t} \t\t\telse \t\t\t{ \t\t\t\ttabs.tabs(); \t\t\t} EOF ); } // Render the tabs in the page (if any) $this->s_content = $this->m_oTabs->RenderIntoContent($this->s_content); // Additional UI widgets to be activated inside the ajax fragment ?? if ($this->sContentType == 'text/html' && (preg_match('/class="date-pick"/', $this->s_content) || preg_match('/class="datetime-pick"/', $this->s_content))) { $this->add_ready_script(<<<EOF \t\$(".date-pick").datepicker({ \t\t\tshowOn: 'button', \t\t\tbuttonImage: '../images/calendar.png', \t\t\tbuttonImageOnly: true, \t\t\tdateFormat: 'yy-mm-dd', \t\t\tconstrainInput: false, \t\t\tchangeMonth: true, \t\t\tchangeYear: true \t\t}); \t\$(".datetime-pick").datepicker({ \t\t\tshowOn: 'button', \t\t\tbuttonImage: '../images/calendar.png', \t\t\tbuttonImageOnly: true, \t\t\tdateFormat: 'yy-mm-dd 00:00:00', \t\t\tconstrainInput: false, \t\t\tchangeMonth: true, \t\t\tchangeYear: true \t\t}); EOF ); } $s_captured_output = $this->ob_get_clean_safe(); if ($this->sContentType == 'text/html' && $this->sContentDisposition == 'inline') { // inline content != attachment && html => filter all scripts for malicious XSS scripts echo self::FilterXSS($this->s_content); } else { echo $this->s_content; } if (!empty($this->m_sMenu)) { $uid = time(); echo "<div id=\"accordion_temp_{$uid}\">\n"; echo "<div id=\"accordion\">\n"; echo "<!-- Beginning of the accordion menu -->\n"; echo self::FilterXSS($this->m_sMenu); echo "<!-- End of the accordion menu-->\n"; echo "</div>\n"; echo "</div>\n"; echo "<script type=\"text/javascript\">\n"; echo "\$('#inner_menu').html(\$('#accordion_temp_{$uid}').html());\n"; echo "\$('#accordion_temp_{$uid}').remove();\n"; echo "\$('#accordion').accordion({ header: 'h3', navigation: true, autoHeight: false, collapsible: false, icons: false });\n"; echo "\n</script>\n"; } //echo $this->s_deferred_content; if (count($this->a_scripts) > 0) { echo "<script type=\"text/javascript\">\n"; echo implode("\n", $this->a_scripts); echo "\n</script>\n"; } if (!empty($this->s_deferred_content)) { echo "<script type=\"text/javascript\">\n"; echo "\$('body').append('" . addslashes(str_replace("\n", '', $this->s_deferred_content)) . "');\n"; echo "\n</script>\n"; } if (!empty($this->m_sReadyScript)) { echo "<script type=\"text/javascript\">\n"; echo $this->m_sReadyScript; // Ready Scripts are output as simple scripts echo "\n</script>\n"; } if (trim($s_captured_output) != "") { echo self::FilterXSS($s_captured_output); } if (class_exists('DBSearch')) { DBSearch::RecordQueryTrace(); } }
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); }
/** * 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(); } }
foreach ($aClassLabels as $sCurrentClass => $sLabel) { $sDescription = MetaModel::GetClassDescription($sCurrentClass); $sSelected = $sCurrentClass == $sBaseClass ? " SELECTED" : ""; $oP->add("<option value=\"{$sCurrentClass}\" title=\"{$sDescription}\"{$sSelected}>{$sLabel}</option>"); } $oP->add("</select>\n"); $oP->add($oAppContext->GetForForm()); $oP->add("</form>\n"); try { if ($sOperation == 'search_form') { $sOQL = "SELECT {$sClass} {$sOQLClause}"; $oFilter = DBObjectSearch::FromOQL($sOQL); } else { // Second part: advanced search form: if (!empty($sFilter)) { $oFilter = DBSearch::unserialize($sFilter); } else { if (!empty($sClass)) { $oFilter = new DBObjectSearch($sClass); } } } } catch (CoreException $e) { $oFilter = new DBObjectSearch($sClass); $oP->P("<b>" . Dict::Format('UI:UniversalSearch:Error', $e->getHtmlDesc()) . "</b>"); } if ($oFilter != null) { $oSet = new CMDBObjectSet($oFilter); $oBlock = new DisplayBlock($oFilter, 'search', false); $aExtraParams = $oAppContext->GetAsHash(); $aExtraParams['open'] = true;
protected function DoExecute() { CMDBSource::Query('START TRANSACTION'); //CMDBSource::Query('ROLLBACK'); automatique ! //////////////////////////////////////////////////////////////////////////////// // Set the stage // $oProvider = new Organization(); $oProvider->Set('name', 'Test-Provider1'); $oProvider->DBInsert(); $iProvider = $oProvider->GetKey(); $oDM1 = new DeliveryModel(); $oDM1->Set('name', 'Test-DM-1'); $oDM1->Set('org_id', $iProvider); $oDM1->DBInsert(); $iDM1 = $oDM1->GetKey(); $oDM2 = new DeliveryModel(); $oDM2->Set('name', 'Test-DM-2'); $oDM2->Set('org_id', $iProvider); $oDM2->DBInsert(); $iDM2 = $oDM2->GetKey(); //////////////////////////////////////////////////////////////////////////////// // Scenarii // $aScenarii = array(array('description' => 'Add the first customer', 'organizations' => array(array('deliverymodel_id' => $iDM1, 'name' => 'Test-Customer-1')), 'expected-res' => array("Test-Customer-1, , active, 0, , {$iDM1}, Test-DM-1, , Test-DM-1"), 'history_added' => 0, 'history_removed' => 0, 'history_modified' => 0), array('description' => 'Remove the customer by loading an empty set', 'organizations' => array(), 'expected-res' => array(), 'history_added' => 0, 'history_removed' => 0, 'history_modified' => 0), array('description' => 'Create two customers at once', 'organizations' => array(array('deliverymodel_id' => $iDM1, 'name' => 'Test-Customer-1'), array('deliverymodel_id' => $iDM1, 'name' => 'Test-Customer-2')), 'expected-res' => array("Test-Customer-1, , active, 0, , {$iDM1}, Test-DM-1, , Test-DM-1", "Test-Customer-2, , active, 0, , {$iDM1}, Test-DM-1, , Test-DM-1"), 'history_added' => 0, 'history_removed' => 0, 'history_modified' => 0), array('description' => 'Move Customer-1 to the second Delivery Model', 'organizations' => array(array('id' => "SELECT Organization WHERE name='Test-Customer-1'", 'deliverymodel_id' => $iDM2, 'name' => 'Test-Customer-1'), array('deliverymodel_id' => $iDM1, 'name' => 'Test-Customer-2')), 'expected-res' => array("Test-Customer-2, , active, 0, , {$iDM1}, Test-DM-1, , Test-DM-1"), 'history_added' => 0, 'history_removed' => 0, 'history_modified' => 0), array('description' => 'Move Customer-1 back to the first Delivery Model and reset Customer-2 (no Delivery Model)', 'organizations' => array(array('id' => "SELECT Organization WHERE name='Test-Customer-1'", 'deliverymodel_id' => $iDM1, 'name' => 'Test-Customer-1'), array('id' => "SELECT Organization WHERE name='Test-Customer-2'", 'deliverymodel_id' => 0, 'name' => 'Test-Customer-2')), 'expected-res' => array("Test-Customer-1, , active, 0, , {$iDM1}, Test-DM-1, , Test-DM-1"), 'history_added' => 0, 'history_removed' => 0, 'history_modified' => 0)); foreach ($aScenarii as $aScenario) { echo "<h4>" . $aScenario['description'] . "</h4>\n"; $oChange = MetaModel::NewObject("CMDBChange"); $oChange->Set("date", time()); $oChange->Set("userinfo", CMDBChange::GetCurrentUserName()); $oChange->Set("origin", 'custom-extension'); $oChange->DBInsert(); CMDBObject::SetCurrentChange($oChange); $iChange = $oChange->GetKey(); // Prepare set $oLinkset = DBObjectSet::FromScratch('Organization'); foreach ($aScenario['organizations'] as $aOrgData) { if (array_key_exists('id', $aOrgData)) { $sOQL = $aOrgData['id']; $oSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL)); $oOrg = $oSet->Fetch(); if (!is_object($oOrg)) { throw new Exception('Failed to find the Organization: ' . $sOQL); } } else { $oOrg = MetaModel::NewObject('Organization'); } foreach ($aOrgData as $sAttCode => $value) { if ($sAttCode == 'id') { continue; } $oOrg->Set($sAttCode, $value); } $oLinkset->AddObject($oOrg); } // Write $oDM = MetaModel::GetObject('DeliveryModel', $iDM1); $oDM->Set('customers_list', $oLinkset); $oDM->DBWrite(); // Check Results $bFoundIssue = false; $oDM = MetaModel::GetObject('DeliveryModel', $iDM1); $oLinkset = $oDM->Get('customers_list'); $aRes = $this->StandardizedDump($oLinkset, 'zzz'); $sRes = var_export($aRes, true); echo "Found: <pre>" . $sRes . "</pre>\n"; $sExpectedRes = var_export($aScenario['expected-res'], true); if ($sRes != $sExpectedRes) { $bFoundIssue = true; echo "NOT COMPLIANT!!! Expecting: <pre>" . $sExpectedRes . "</pre>\n"; } // Check History $aQueryParams = array('change' => $iChange, 'objclass' => get_class($oDM), 'objkey' => $oDM->GetKey()); $oAdded = new DBObjectSet(DBSearch::FromOQL("SELECT CMDBChangeOpSetAttributeLinksAddRemove WHERE objclass = :objclass AND objkey = :objkey AND change = :change AND type = 'added'"), array(), $aQueryParams); echo "added: " . $oAdded->Count() . "<br/>\n"; if ($aScenario['history_added'] != $oAdded->Count()) { $bFoundIssue = true; echo "NOT COMPLIANT!!! Expecting: " . $aScenario['history_added'] . "<br/>\n"; } $oRemoved = new DBObjectSet(DBSearch::FromOQL("SELECT CMDBChangeOpSetAttributeLinksAddRemove WHERE objclass = :objclass AND objkey = :objkey AND change = :change AND type = 'removed'"), array(), $aQueryParams); echo "removed: " . $oRemoved->Count() . "<br/>\n"; if ($aScenario['history_removed'] != $oRemoved->Count()) { $bFoundIssue = true; echo "NOT COMPLIANT!!! Expecting: " . $aScenario['history_removed'] . "<br/>\n"; } $oModified = new DBObjectSet(DBSearch::FromOQL("SELECT CMDBChangeOpSetAttributeLinksTune WHERE objclass = :objclass AND objkey = :objkey AND change = :change"), array(), $aQueryParams); echo "modified: " . $oModified->Count() . "<br/>\n"; if ($aScenario['history_modified'] != $oModified->Count()) { $bFoundIssue = true; echo "NOT COMPLIANT!!! Expecting: " . $aScenario['history_modified'] . "<br/>\n"; } if ($bFoundIssue) { throw new Exception('Stopping on failed scenario'); } } }