diff --git a/application/itopwebpage.class.inc.php b/application/itopwebpage.class.inc.php index d49de0bfaf..5b48177d25 100644 --- a/application/itopwebpage.class.inc.php +++ b/application/itopwebpage.class.inc.php @@ -1,26 +1,26 @@ - * @author Romain Quetiez - * @author Denis Flaven - * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL + * @author Erwan Taloc + * @author Romain Quetiez + * @author Denis Flaven + * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL */ require_once(APPROOT."/application/nicewebpage.class.inc.php"); @@ -32,13 +32,13 @@ require_once(APPROOT."/application/user.preferences.class.inc.php"); class iTopWebPage extends NiceWebPage { private $m_sMenu; -// private $m_currentOrganization; + // private $m_currentOrganization; private $m_aTabs; private $m_sCurrentTabContainer; private $m_sCurrentTab; private $m_sMessage; private $m_sInitScript; - + public function __construct($sTitle) { parent::__construct($sTitle); @@ -83,46 +83,46 @@ class iTopWebPage extends NiceWebPage // Layout paneSize = GetUserPreference('menu_size', 300) myLayout = $('body').layout({ - west : { + west : { minSize: 200, size: paneSize, spacing_open: 16, spacing_close: 16, slideTrigger_open: "mouseover", hideTogglerOnSlide: true, - onclose_end: function(name, elt, state, options, layout) - { - if (state.isSliding == false) - { - SetUserPreference('menu_pane', 'closed', true); - } - }, - onresize_end: function(name, elt, state, options, layout) - { - if (state.isSliding == false) - { - SetUserPreference('menu_size', state.size, true); - } - }, - - onopen_end: function(name, elt, state, options, layout) - { - if (state.isSliding == false) - { - SetUserPreference('menu_pane', 'open', true); - } - } + onclose_end: function(name, elt, state, options, layout) + { + if (state.isSliding == false) + { + SetUserPreference('menu_pane', 'closed', true); + } + }, + onresize_end: function(name, elt, state, options, layout) + { + if (state.isSliding == false) + { + SetUserPreference('menu_size', state.size, true); + } + }, + + onopen_end: function(name, elt, state, options, layout) + { + if (state.isSliding == false) + { + SetUserPreference('menu_pane', 'open', true); + } + } }, - center: { - onresize_end: function(name, elt, state, options, layout) - { - $('.v-resizable').each( function() { - var fixedWidth = $(this).parent().innerWidth() - 6; - $(this).width(fixedWidth); - // Make sure it cannot be resized horizontally - $(this).resizable('options', { minWidth: fixedWidth, maxWidth: fixedWidth }); + center: { + onresize_end: function(name, elt, state, options, layout) + { + $('.v-resizable').each( function() { + var fixedWidth = $(this).parent().innerWidth() - 6; + $(this).width(fixedWidth); + // Make sure it cannot be resized horizontally + $(this).resizable('options', { minWidth: fixedWidth, maxWidth: fixedWidth }); // Now adjust all the child 'items' - var innerWidth = $(this).innerWidth() - 10; - $(this).find('.item').width(innerWidth); - }); - } + var innerWidth = $(this).innerWidth() - 10; + $(this).find('.item').width(innerWidth); + }); + } - } + } }); myLayout.addPinBtn( "#tPinMenu", "west" ); //myLayout.open( "west" ); @@ -138,7 +138,7 @@ class iTopWebPage extends NiceWebPage // Tabs, using JQuery BBQ to store the history // The "tab widgets" to handle. var tabs = $('div[id^=tabbedContent]'); - + // This selector will be reused when selecting actual tab widget A elements. var tab_a_selector = 'ul.ui-tabs-nav a'; @@ -159,16 +159,16 @@ class iTopWebPage extends NiceWebPage alert(err); } EOF -; + ; $this->add_ready_script( <<< EOF //add new widget called TruncatedList to properly display truncated lists when they are sorted $.tablesorter.addWidget({ - // give the widget a id - id: "truncatedList", - // format is called when the on init and when a sorting has finished - format: function(table) - { + // give the widget a id + id: "truncatedList", + // format is called when the on init and when a sorting has finished + format: function(table) + { // Check if there is a "truncated" line this.truncatedList = false; if ($("tr td.truncated",table).length > 0) @@ -180,17 +180,17 @@ EOF $("tr td",table).removeClass('truncated'); $("tr:last td",table).addClass('truncated'); } - } + } }); $.tablesorter.addWidget({ - // give the widget a id - id: "myZebra", - // format is called when the on init and when a sorting has finished - format: function(table) - { - // Replace the 'red even' lines by 'red_even' since most browser do not support 2 classes selector in CSS, etc.. + // give the widget a id + id: "myZebra", + // format is called when the on init and when a sorting has finished + format: function(table) + { + // Replace the 'red even' lines by 'red_even' since most browser do not support 2 classes selector in CSS, etc.. $("tbody tr:even",table).addClass('even'); $("tbody tr.red:even",table).removeClass('red').removeClass('even').addClass('red_even'); $("tbody tr.orange:even",table).removeClass('orange').removeClass('even').addClass('orange_even'); @@ -200,7 +200,7 @@ EOF $("tbody tr.red_even:odd",table).removeClass('even').removeClass('red_even').addClass('red'); $("tbody tr.orange_even:odd",table).removeClass('even').removeClass('orange_even').addClass('orange'); $("tbody tr.green_even:odd",table).removeClass('even').removeClass('green_even').addClass('green'); - } + } }); // Adjust initial size @@ -238,7 +238,7 @@ EOF // Tabs, using JQuery BBQ to store the history // The "tab widgets" to handle. var tabs = $('div[id^=tabbedContent]'); - + // This selector will be reused when selecting actual tab widget A elements. var tab_a_selector = 'ul.ui-tabs-nav a'; @@ -325,13 +325,13 @@ EOF { var aSerialized = sTemp.split(','); var sortable = $(this); - $.each(aSerialized, function(i,v) { - var item = $('#menu_'+v); - if (item.length > 0) // Check that the menu exists - { - sortable.append(item); - } - }); + $.each(aSerialized, function(i,v) { + var item = $('#menu_'+v); + if (item.length > 0) // Check that the menu exists + { + sortable.append(item); + } + }); } }); @@ -354,7 +354,7 @@ EOF $('.caselog_header').click( function () { $(this).toggleClass('open').next('.caselog_entry').toggle(); }); EOF -); + ); $sUserPrefs = appUserPreferences::GetAsJSON(); $this->add_script( << div').html() != '') { $('#rawOutput').dialog( {autoOpen: true, modal:false}); - } - } - - function AddAppContext(sURL) - { - var sContext = '$sAppContext'; + } + } + + function AddAppContext(sURL) + { + var sContext = '$sAppContext'; if (sContext.length > 0) { if (sURL.indexOf('?') == -1) @@ -421,22 +421,22 @@ EOF // For disabling the CKEditor at init time when the corresponding textarea is disabled ! CKEDITOR.plugins.add( 'disabler', { - init : function( editor ) - { - editor.on( 'instanceReady', function(e) - { - e.removeListener(); - $('#'+ editor.name).trigger('update'); - }); - } - + init : function( editor ) + { + editor.on( 'instanceReady', function(e) + { + e.removeListener(); + $('#'+ editor.name).trigger('update'); + }); + } + }); EOF -); - - // Build menus from module handlers - // + ); + + // Build menus from module handlers + // foreach(get_declared_classes() as $sPHPClass) { if (is_subclass_of($sPHPClass, 'ModuleHandlerAPI')) @@ -446,7 +446,7 @@ EOF } } } - + public function AddToMenu($sHtml) { $this->m_sMenu .= $sHtml; @@ -465,7 +465,7 @@ EOF $oSearchFilter->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', true); $oSet = new CMDBObjectSet($oSearchFilter); $iCount = $oSet->Count(); // total number of existing Orgs - + // Now get the list of Orgs to be displayed in the menu $oSearchFilter = DBObjectSearch::FromOQL(ApplicationMenu::GetFavoriteSiloQuery()); $oSearchFilter->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', true); @@ -481,39 +481,21 @@ EOF // No such dimension/silo => nothing to select $sHtml = '
'; break; - + case 1: // Only one possible choice... no selection, but display the value $oOrg = $oSet->Fetch(); $sHtml = '
'.$oOrg->GetName().'
'; $sHtml .= ''; break; - + default: $sHtml = ''; $oAppContext = new ApplicationContext(); $iCurrentOrganization = $oAppContext->GetCurrentValue('org_id'); $sHtml = '
'; $sHtml .= '
'; //'; -*/ + $sFavoriteOrgs = ''; $oWidget = new UIExtKeyWidget('Organization', 'org_id', '', true /* search mode */); $sHtml .= $oWidget->Display($this, 50, false, '', $oSet, $iCurrentOrganization, 'org_id', false, 'c[org_id]', '', array('iFieldSize' => 20, 'iMinChars' => MetaModel::GetConfig()->Get('min_autocomplete_chars'), 'sDefaultValue' => Dict::S('UI:AllOrganizations'))); @@ -526,25 +508,25 @@ EOF $sHtml .= '
'; $sHtml .= '
'; } - return $sHtml; + return $sHtml; } - - public function DisplayMenu() - { + + public function DisplayMenu() + { // Display the menu $oAppContext = new ApplicationContext(); $iAccordionIndex = 0; ApplicationMenu::DisplayMenu($this, $oAppContext->GetAsHash()); - } + } /** * Outputs (via some echo) the complete HTML page by assembling all its elements */ - public function output() - { - $sAbsURLAppRoot = addslashes($this->m_sRootUrl); - $sAbsURLModulesRoot = addslashes(utils::GetAbsoluteUrlModulesRoot()); + public function output() + { + $sAbsURLAppRoot = addslashes($this->m_sRootUrl); + $sAbsURLModulesRoot = addslashes(utils::GetAbsoluteUrlModulesRoot()); $this->add_script( <<DisplayMenu(); // Compute the menu // Put here the 'ready scripts' that must be executed after all others - $this->add_ready_script( + $this->add_ready_script( <<a_headers as $s_header) - { - header($s_header); - } - $s_captured_output = ob_get_contents(); - ob_end_clean(); - echo "\n"; - echo "\n"; - echo "\n"; - // Make sure that Internet Explorer renders the page using its latest/highest/greatest standards ! - echo "\n"; - echo "\n"; - echo "".htmlentities($this->s_title, ENT_QUOTES, 'UTF-8')."\n"; - echo $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'] != "") - { - echo "\n"; - } - } - 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 "\n"; - } - $this->add_script("\$(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) - { - echo "\n"; - } - - if (count($this->a_styles)>0) - { - echo "\n"; - } - echo "\n"; - echo "\n"; + // Since the event is only triggered when the hash changes, we need to trigger + // the event now, to handle the hash the page may have loaded with. + $(window).trigger( 'hashchange' ); - echo "\n"; - echo "\n"; + // Some table are sort-able, some are not, let's fix this + $('table.listResults').each( function() { FixTableSorter($(this)); } ); +EOF + ); + if ($this->GetOutputFormat() == 'html') + { + foreach($this->a_headers as $s_header) + { + header($s_header); + } + } + $s_captured_output = ob_get_contents(); + ob_end_clean(); + $sHtml = "\n"; + $sHtml .= "\n"; + $sHtml .= "\n"; + // Make sure that Internet Explorer renders the page using its latest/highest/greatest standards ! + $sHtml .= "\n"; + $sHtml .= "\n"; + $sHtml .= "".htmlentities($this->s_title, ENT_QUOTES, 'UTF-8')."\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 .= "\n"; + } + } + // special stylesheet for printing, hides the navigation gadgets + $sHtml .= "\n"; + + if ($this->GetOutputFormat() == 'html') + { + 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 .= "\n"; + } + $this->add_script("\$(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 .= "\n"; + } + } + + if (count($this->a_styles)>0) + { + $sHtml .= "\n"; + } + $sHtml .= "\n"; + $sHtml .= "\n"; + + $sHtml .= "\n"; + $sHtml .= "\n"; @@ -673,7 +663,7 @@ EOF // 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) foreach($this->m_aTabs as $sTabContainerName => $m_aTabs) { @@ -681,159 +671,189 @@ EOF $container_index = 0; if (count($m_aTabs) > 0) { - $sTabs = "\n
\n"; - $sTabs .= "\n"; - // Now add the content of the tabs themselves - $i = 0; - foreach($m_aTabs as $sTabName => $sTabContent) - { - $sTabs .= "
".$sTabContent."
\n"; - $i++; - } - $sTabs .= "
\n\n"; - } + $sTabs = "\n
\n"; + $sTabs .= "\n"; + // Now add the content of the tabs themselves + $i = 0; + foreach($m_aTabs as $sTabName => $sTabContent) + { + $sTabs .= "
".$sTabContent."
\n"; + $i++; + } + $sTabs .= "
\n\n"; + } $this->s_content = str_replace("\$Tabs:$sTabContainerName\$", $sTabs, $this->s_content); $container_index++; } - $sUserName = UserRights::GetUser(); - $sIsAdmin = UserRights::IsAdministrator() ? '(Administrator)' : ''; - if (UserRights::IsAdministrator()) + + if ($this->GetOutputFormat() == 'html') { - $sLogonMessage = Dict::Format('UI:LoggedAsMessage+Admin', $sUserName); + $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 = "\n"; + + $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 .= '
'; + $sApplicationBanner .= ''; + $sApplicationBanner .= ' '.$sRestrictions.''; + if (strlen($sAdminMessage) > 0) + { + $sApplicationBanner .= ' '.$sAdminMessage.''; + } + $sApplicationBanner .= '
'; + } + + if(strlen($this->m_sMessage)) + { + $sApplicationBanner .= '
'.$this->m_sMessage.'
'; + } + + $sEnvironment = utils::GetCurrentEnvironment(); + $sBackButton = utils::GetEnvironmentBackButton(); + if($sEnvironment != 'production') + { + $sEnvLabel = trim(MetaModel::GetConfig()->Get('app_env_label')); + if (strlen($sEnvLabel) == 0) + { + $sEnvLabel = $sEnvironment; + } + $sApplicationBanner .= '
'.Dict::Format('UI:ApplicationEnvironment', $sEnvLabel).$sBackButton.'
'; + } + + $sOnlineHelpUrl = MetaModel::GetConfig()->Get('online_help'); + //$sLogOffMenu = ""; + + $sHtml .= '
'; + $sHtml .= ''; + $sHtml .= ' '; + $sHtml .= '
'; + $sHtml .= '
pin
'; + $sHtml .= '
'.self::FilterXSS($sForm).'
'; + $sHtml .= '
'; + $sHtml .= ' '; + $sHtml .= ' '; + $sHtml .= ''; + $sHtml .= '
'; + + $sHtml .= '
'; + $sHtml .= '
'; + $sHtml .= self::FilterXSS($sApplicationBanner); + $sHtml .= ' '; + //echo '        
'; + $sHtml .= '
'; + $sHtml .= '
'; + $sHtml .= ' '; + $sHtml .= self::FilterXSS($this->s_content); + $sHtml .= ' '; + $sHtml .= '
'; + $sHtml .= ''; + + // Add the captured output + if (trim($s_captured_output) != "") + { + $sHtml .= "
".self::FilterXSS($s_captured_output)."
\n"; + } + $sHtml .= "
".self::FilterXSS($this->s_deferred_content)."
"; + $sHtml .= "
Please wait...
\n"; // jqModal Window + $sHtml .= "
"; + $sHtml .= "
"; } else { - $sLogonMessage = Dict::Format('UI:LoggedAsMessage', $sUserName); + $sHtml .= self::FilterXSS($this->s_content); } - $sLogOffMenu = "\n"; - $sRestrictions = ''; - if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE)) + $sHtml .= "\n"; + $sHtml .= "\n"; + + if ($this->GetOutputFormat() == 'html') { - if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE)) + echo $sHtml; + } + else if ($this->GetOutputFormat() == 'pdf' && $this->IsOutputFormatAvailable('pdf') ) + { + require_once(APPROOT.'lib/MPDF/mpdf.php'); + $oMPDF = new mPDF('c'); + $oMPDF->mirroMargins = false; + if ($this->a_base['href'] != '') { - $sRestrictions = Dict::S('UI:AccessRO-All'); + $oMPDF->setBasePath($this->a_base['href']); // Seems that the tag is not recognized by mPDF... } - } - 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 .= '
'; - $sApplicationBanner .= ''; - $sApplicationBanner .= ' '.$sRestrictions.''; - if (strlen($sAdminMessage) > 0) + $oMPDF->showWatermarkText = true; + if ($this->GetOutputOption('pdf', 'template_path')) { - $sApplicationBanner .= ' '.$sAdminMessage.''; + $oMPDF->setImportUse(); // Allow templates + $oMPDF->SetDocTemplate ($this->GetOutputOption('pdf', 'template_path'), 1); } - $sApplicationBanner .= '
'; + $oMPDF->WriteHTML($sHtml); + $oMPDF->Output(); } + } - if(strlen($this->m_sMessage)) - { - $sApplicationBanner .= '
'.$this->m_sMessage.'
'; - } - - $sEnvironment = utils::GetCurrentEnvironment(); - $sBackButton = utils::GetEnvironmentBackButton(); - if($sEnvironment != 'production') - { - $sEnvLabel = trim(MetaModel::GetConfig()->Get('app_env_label')); - if (strlen($sEnvLabel) == 0) - { - $sEnvLabel = $sEnvironment; - } - $sApplicationBanner .= '
'.Dict::Format('UI:ApplicationEnvironment', $sEnvLabel).$sBackButton.'
'; - } - - $sOnlineHelpUrl = MetaModel::GetConfig()->Get('online_help'); - //$sLogOffMenu = ""; - - echo '
'; - echo ''; - echo ' '; - echo '
'; - echo '
pin
'; - echo '
'.self::FilterXSS($sForm).'
'; - echo '
'; - echo ' '; - echo ' '; - echo ''; - echo '
'; - - echo '
'; - echo '
'; - echo self::FilterXSS($sApplicationBanner); - echo ' '; - //echo '        
'; - echo '
'; - echo '
'; - echo ' '; - echo self::FilterXSS($this->s_content); - echo ' '; - echo '
'; - echo ''; - - // Add the captured output - if (trim($s_captured_output) != "") - { - echo "
".self::FilterXSS($s_captured_output)."
\n"; - } - echo "
".self::FilterXSS($this->s_deferred_content)."
"; -// echo $this->s_deferred_content; - echo "
Please wait...
\n"; // jqModal Window - echo "
"; - echo "
"; - - echo "\n"; - echo "\n"; - } - public function AddTabContainer($sTabContainer) { $this->m_aTabs[$sTabContainer] = array(); $this->add("\$Tabs:$sTabContainer\$"); } - + public function AddToTab($sTabContainer, $sTabLabel, $sHtml) { if (!isset($this->m_aTabs[$sTabContainer][$sTabLabel])) @@ -861,12 +881,12 @@ EOF $this->m_sCurrentTab = $sTabLabel; return $sPreviousTab; } - + public function GetCurrentTab() { return $this->m_sCurrentTab; } - + public function RemoveTab($sTabLabel, $sTabContainer = null) { if ($sTabContainer == null) @@ -877,7 +897,7 @@ EOF { // Delete the content of the tab unset($this->m_aTabs[$sTabContainer][$sTabLabel]); - + // If we just removed the active tab, let's reset the active tab if (($this->m_sCurrentTabContainer == $sTabContainer) && ($this->m_sCurrentTab == $sTabLabel)) { @@ -907,7 +927,7 @@ EOF } return $result; } - + /** * Make the given tab the active one, as if it were clicked * DOES NOT WORK: apparently in the *old* version of jquery @@ -929,7 +949,7 @@ EOF break; } $tab_index++; - } + } break; } $container_index++; @@ -937,7 +957,7 @@ EOF $sSelector = '#tabbedContent_'.$container_index.' > ul'; $this->add_ready_script("$('$sSelector').tabs('select', $tab_index);"); } - + public function StartCollapsibleSection($sSectionLabel, $bOpen = false) { $this->add($this->GetStartCollapsibleSection($sSectionLabel, $bOpen)); @@ -967,91 +987,68 @@ EOF return ""; } - public function add($sHtml) - { - if (!empty($this->m_sCurrentTabContainer) && !empty($this->m_sCurrentTab)) - { - $this->AddToTab($this->m_sCurrentTabContainer, $this->m_sCurrentTab, $sHtml); - } - else - { - parent::add($sHtml); - } - } - + public function add($sHtml) + { + if (!empty($this->m_sCurrentTabContainer) && !empty($this->m_sCurrentTab)) + { + $this->AddToTab($this->m_sCurrentTabContainer, $this->m_sCurrentTab, $sHtml); + } + else + { + parent::add($sHtml); + } + } + /** * Records the current state of the 'html' part of the page output * @return mixed The current state of the 'html' output - */ - public function start_capture() - { - if (!empty($this->m_sCurrentTabContainer) && !empty($this->m_sCurrentTab)) - { - $iOffset = isset($this->m_aTabs[$this->m_sCurrentTabContainer][$this->m_sCurrentTab]) ? strlen($this->m_aTabs[$this->m_sCurrentTabContainer][$this->m_sCurrentTab]): 0; - return array('tc' => $this->m_sCurrentTabContainer, 'tab' => $this->m_sCurrentTab, 'offset' => $iOffset); - } - else - { - return parent::start_capture(); - } - } - - /** - * Returns the part of the html output that occurred since the call to start_capture - * and removes this part from the current html output - * @param $offset mixed The value returned by start_capture - * @return string The part of the html output that was added since the call to start_capture - */ - public function end_capture($offset) - { - if (is_array($offset)) - { - if (isset($this->m_aTabs[$offset['tc']][$offset['tab']])) - { - $sCaptured = substr($this->m_aTabs[$offset['tc']][$offset['tab']], $offset['offset']); - $this->m_aTabs[$offset['tc']][$offset['tab']] = substr($this->m_aTabs[$offset['tc']][$offset['tab']], 0, $offset['offset']); - } - else - { - $sCaptured = ''; - } - } - else - { - $sCaptured = parent::end_capture($offset); - } - return $sCaptured; - } - - /** - * Set the message to be displayed in the 'admin-banner' section at the top of the page - */ - public function SetMessage($sMessage) - { - $this->m_sMessage = $sMessage; - } - - /* - public function AddSearchForm($sClassName, $bOpen = false) - { - $iSearchSectionId = 0; - - $sStyle = $bOpen ? 'SearchDrawer' : 'SearchDrawer DrawerClosed'; - $this->add("
\n"); - $this->add("

Search form for ".Metamodel::GetName($sClassName)."

\n"); - $this->add_ready_script("\$(\"#LnkSearch_$iSearchSectionId\").click(function() {\$(\"#Search_$iSearchSectionId\").slideToggle('normal'); $(\"#LnkSearch_$iSearchSectionId\").toggleClass('open');});"); - $oFilter = new DBObjectSearch($sClassName); - $sFilter = $oFilter->serialize(); - $oSet = new CMDBObjectSet($oFilter); - cmdbAbstractObject::DisplaySearchForm($this, $oSet, array('operation' => 'search', 'filter' => $sFilter, 'search_form' => true)); - $this->add("
\n"); - $this->add("
\n"); - $this->add("
Search
\n"); - - - $iSearchSectionId++; + */ + public function start_capture() + { + if (!empty($this->m_sCurrentTabContainer) && !empty($this->m_sCurrentTab)) + { + $iOffset = isset($this->m_aTabs[$this->m_sCurrentTabContainer][$this->m_sCurrentTab]) ? strlen($this->m_aTabs[$this->m_sCurrentTabContainer][$this->m_sCurrentTab]): 0; + return array('tc' => $this->m_sCurrentTabContainer, 'tab' => $this->m_sCurrentTab, 'offset' => $iOffset); + } + else + { + return parent::start_capture(); + } } - */ -} -?> + /** + * Returns the part of the html output that occurred since the call to start_capture + * and removes this part from the current html output + * @param $offset mixed The value returned by start_capture + * @return string The part of the html output that was added since the call to start_capture + */ + public function end_capture($offset) + { + if (is_array($offset)) + { + if (isset($this->m_aTabs[$offset['tc']][$offset['tab']])) + { + $sCaptured = substr($this->m_aTabs[$offset['tc']][$offset['tab']], $offset['offset']); + $this->m_aTabs[$offset['tc']][$offset['tab']] = substr($this->m_aTabs[$offset['tc']][$offset['tab']], 0, $offset['offset']); + } + else + { + $sCaptured = ''; + } + } + else + { + $sCaptured = parent::end_capture($offset); + } + return $sCaptured; + } + + /** + * Set the message to be displayed in the 'admin-banner' section at the top of the page + */ + public function SetMessage($sMessage) + { + $this->m_sMessage = $sMessage; + } +} +?> \ No newline at end of file diff --git a/application/webpage.class.inc.php b/application/webpage.class.inc.php index 5246653b39..65431aa83d 100644 --- a/application/webpage.class.inc.php +++ b/application/webpage.class.inc.php @@ -50,6 +50,8 @@ class WebPage protected $sContentType; protected $sContentDisposition; protected $sContentFileName; + protected $s_sOutputFormat; + protected $a_OutputOptions; public function __construct($s_title) { @@ -67,6 +69,8 @@ class WebPage $this->sContentType = ''; $this->sContentDisposition = ''; $this->sContentFileName = ''; + $this->s_OutputFormat = utils::ReadParam('output_format', 'html'); + $this->a_OutputOptions = array(); ob_start(); // Start capturing the output } @@ -515,5 +519,67 @@ class WebPage { return str_ireplace('s_OutputFormat; + } + + /** + * Check whether the desired output format is possible or not + * @param string $sOutputFormat The desired output format: html, pdf... + * @return bool True if the format is Ok, false otherwise + */ + function IsOutputFormatAvailable($sOutputFormat) + { + $bResult = false; + switch($sOutputFormat) + { + case 'html': + $bResult = true; // Always supported + break; + + case 'pdf': + $bResult = @is_readable(APPROOT.'lib/MPDF/mpdf.php'); + break; + } + return $bResult; + } + + /** + * Retrieves the value of a named output option for the given format + * @param string $sFormat The format: html or pdf + * @param string $sOptionName The name of the option + * @return mixed false if the option was never set or the options's value + */ + public function GetOutputOption($sFormat, $sOptionName) + { + if (isset($this->a_OutputOptions[$sFormat][$sOptionName])) + { + return $this->a_OutputOptions[$sFormat][$sOptionName]; + } + return false; + } + /** + * Sets a named output option for the given format + * @param string $sFormat The format for which to set the option: html or pdf + * @param string $sOptionName the name of the option + * @param mixed $sValue The value of the option + */ + public function SetOutputOption($sFormat, $sOptionName, $sValue) + { + if (!isset($this->a_OutputOptions[$sFormat])) + { + $this->a_OutputOptions[$sFormat] = array($sOptionName => $sValue); + } + else + { + $this->a_OutputOptions[$sFormat][$sOptionName] = $sValue; + } + } } ?> \ No newline at end of file