* @author Romain Quetiez * @author Denis Flaven * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL */ require_once("../application/nicewebpage.class.inc.php"); require_once("../application/usercontext.class.inc.php"); require_once("../application/applicationcontext.class.inc.php"); /** * Web page with some associated CSS and scripts (jquery) for a fancier display */ class iTopWebPage extends NiceWebPage { private $m_sMenu; private $m_currentOrganization; private $m_aTabs; private $m_sCurrentTabContainer; private $m_sCurrentTab; public function __construct($sTitle, $currentOrganization) { parent::__construct($sTitle); $this->m_sCurrentTabContainer = ''; $this->m_sCurrentTab = ''; $this->m_aTabs = array(); $this->m_sMenu = ""; $oAppContext = new ApplicationContext(); $sExtraParams = $oAppContext->GetForLink(); $this->m_currentOrganization = $currentOrganization; $this->add_header("Content-type: text/html; charset=utf-8"); $this->add_header("Cache-control: no-cache"); $this->add_linked_stylesheet("../css/jquery.treeview.css"); $this->add_linked_stylesheet("../css/jquery.autocomplete.css"); // $this->add_linked_stylesheet("../css/date.picker.css"); $this->add_linked_script('../js/jquery.layout.min.js'); // $this->add_linked_script("../js/jquery.dimensions.js"); $this->add_linked_script("../js/jquery.tablehover.js"); $this->add_linked_script("../js/jquery.treeview.js"); $this->add_linked_script("../js/jquery.autocomplete.js"); $this->add_linked_script("../js/jquery.bgiframe.js"); $this->add_linked_script("../js/jquery.positionBy.js"); $this->add_linked_script("../js/jquery.popupmenu.js"); $this->add_linked_script("../js/date.js"); // $this->add_linked_script("../js/jquery.date.picker.js"); $this->add_linked_script("../js/jquery.tablesorter.min.js"); $this->add_linked_script("../js/jquery.blockUI.js"); $this->add_linked_script("../js/utils.js"); $this->add_linked_script("../js/swfobject.js"); $this->add_ready_script( << 0) { this.truncatedList = true; } if (this.truncatedList) { $("tr td",table).removeClass('truncated'); $("tr:last td",table).addClass('truncated'); } } }); try { var myLayout; // a var is required because this page utilizes: myLayout.allowOverflow() method $(document).ready(function () { // Layout myLayout = $('body').layout({ west : { minSize: 200, size: 300 /* TO DO: read from a cookie ?*/, spacing_open: 16, spacing_close: 16, slideTrigger_open: "mouseover", hideTogglerOnSlide: true } }); myLayout.addPinBtn( "#tPinMenu", "west" ); //myLayout.open( "west" ); $('.ui-layout-resizer-west').html(''); // Accordion Menu $("#accordion").accordion({ header: "h3", navigation: true, autoHeight: false }); }); //$("div[id^=tabbedContent] > ul").tabs( 1, { fxFade: true, fxSpeed: 'fast' } ); // tabs $("div[id^=tabbedContent]").tabs(); // tabs $("table.listResults").tableHover(); // hover tables $(".listResults").tablesorter( { headers: { 0:{sorter: false }}, widgets: ['zebra', 'truncatedList']} ); // sortable and zebra tables $(".date-pick").datepicker({ showOn: 'button', buttonImage: '../images/calendar.png', buttonImageOnly: true, dateFormat: 'yy-mm-dd', constrainInput: false, changeMonth: true, changeYear: true }); $('.resizable').resizable(); // Make resizable everything that claims to be resizable ! docWidth = $(document).width(); $('#ModalDlg').dialog({ autoOpen: false, modal: true, width: 0.8*docWidth }); // JQuery UI dialogs ShowDebug(); $('#logOffBtn>ul').popupmenu(); } catch(err) { // Do something with the error ! } //$('.display_block').draggable(); // make the blocks draggable EOF ); $this->add_script(" // For automplete function findValue(li) { if( li == null ) return alert(\"No match!\"); // if coming from an AJAX call, let's use the CityId as the value if( !!li.extra ) var sValue = li.extra[0]; // otherwise, let's just display the value in the text box else var sValue = li.selectValue; //alert(\"The value you selected was: \" + sValue); } function selectItem(li) { findValue(li); } function formatItem(row) { return row[0]; } function goBack() { window.history.back(); } function BackToDetails(sClass, id) { window.location.href = './UI.php?operation=details&class='+sClass+'&id='+id; } function ShowDebug() { if ($('#rawOutput > div').html() != '') { $('#rawOutput').dialog( {autoOpen: true, modal:false}); } } "); $this->DisplayMenu(); } public function AddToMenu($sHtml) { $this->m_sMenu .= $sHtml; } public function GetSiloSelectionForm() { $sHtml = '
'; $sHtml .= '
'; // Add other dimensions/context information to this form $oAppContext = new ApplicationContext(); $oAppContext->Reset('org_id'); // Org id is handled above and we want to be able to change it here ! $sHtml .= $oAppContext->GetForForm(); $sHtml .= '
'; $sHtml .= '
'; return $sHtml; } public function DisplayMenu() { $oContext = new UserContext(); // Display the menu $oAppContext = new ApplicationContext(); $iActiveNodeId = utils::ReadParam('menu', ''); $iAccordionIndex = 0; // 1) Application defined menus $oSearchFilter = $oContext->NewFilter("menuNode"); $oSearchFilter->AddCondition('parent_id', 0, '='); $oSearchFilter->AddCondition('type', 'application', '='); // There may be more criteria added later to have a specific menu based on the user's profile $oSet = new CMDBObjectSet($oSearchFilter, array('rank' => true)); while ($oRootMenuNode = $oSet->Fetch()) { $bResult = $oRootMenuNode->DisplayMenu($this, 'application', $oAppContext->GetAsHash(), true, $iActiveNodeId); if ($bResult) { $this->add_ready_script("$('#accordion').accordion('activate', $iAccordionIndex)"); } $iAccordionIndex++; } // 2) User defined menus (Bookmarks) $oSearchFilter = $oContext->NewFilter("menuNode"); $oSearchFilter->AddCondition('parent_id', 0, '='); $oSearchFilter->AddCondition('type', 'user', '='); $oSearchFilter->AddCondition('user_id', UserRights::GetUserId(), '='); // There may be more criteria added later to have a specific menu based on the user's profile $oSet = new CMDBObjectSet($oSearchFilter, array('rank' => true)); while ($oRootMenuNode = $oSet->Fetch()) { $oRootMenuNode->DisplayMenu($this, 'user', $oAppContext->GetAsHash(), true, $iActiveNodeId); if ($bResult) { $this->add_ready_script("$('#accordion').accordion('activate', $iAccordionIndex)"); } $iAccordionIndex++; } // 3) Administrator menu if (userRights::IsAdministrator()) { $oSearchFilter = $oContext->NewFilter("menuNode"); $oSearchFilter->AddCondition('parent_id', 0, '='); $oSearchFilter->AddCondition('type', 'administrator', '='); // There may be more criteria added later to have a specific menu based on the user's profile $oSet = new CMDBObjectSet($oSearchFilter, array('rank' => true)); while ($oRootMenuNode = $oSet->Fetch()) { $oRootMenuNode->DisplayMenu($this, 'administrator', $oAppContext->GetAsHash(), true, $iActiveNodeId); if ($bResult) { $this->add_ready_script("$('#accordion').accordion('activate', $iAccordionIndex)"); } $iAccordionIndex++; } } $this->AddToMenu("\n"); } /** * 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 = ob_get_contents(); ob_end_clean(); echo "\n"; echo "\n"; echo "\n"; echo "{$this->s_title}\n"; echo "\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) { echo "\n"; } if (count($this->m_aReadyScripts)>0) { $this->add_script("\$(document).ready(function() {\n".implode("\n", $this->m_aReadyScripts)."\n});"); } if (count($this->a_scripts)>0) { echo "\n"; } if (count($this->a_styles)>0) { echo "\n"; } echo "\n"; echo "\n"; echo "\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 = "iTop Version ".ITOP_VERSION; } else { // This is a build made from SVN, let display the full information $sVersionString = "iTop Version ".ITOP_VERSION." revision ".ITOP_REVISION.", built on: ".ITOP_BUILD_DATE; } // Render the text of the global search form $sText = Utils::ReadParam('text', ''); $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;\""; } $sForm = $this->GetSiloSelectionForm(); // Render the tabs in the page (if any) foreach($this->m_aTabs as $sTabContainerName => $m_aTabs) { $sTabs = ''; $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"; } $this->s_content = str_replace("\$Tabs:$sTabContainerName\$", $sTabs, $this->s_content); $container_index++; } $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 = "
    • "; $sLogOffMenu .= "
    • $sLogonMessage
    • \n"; $sLogOffMenu .= "
    • Log Off
    • \n"; $sLogOffMenu .= "
    • Change password...
    • \n"; $sLogOffMenu .= "
    \n
  • \n
\n"; //$sLogOffMenu = ""; echo '
'; echo ''; echo ' '; echo '
'; echo '
pin
'; echo '
'.$sForm.'
'; echo '
'; echo ' '; echo ' '; echo ''; echo '
'; echo '
'; echo '
'; echo ' '; //echo '        
'; echo '
'; echo '
'; echo ' '; echo $this->s_content; echo ' '; echo '
'; echo ''; /* echo "
iTop
\n"; //echo "
\n"; $sText = Utils::ReadParam('text', ''); $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;\""; } $sUserName = UserRights::GetUser(); $sIsAdmin = UserRights::IsAdministrator() ? '(Administrator)' : ''; if (UserRights::IsAdministrator()) { $sLogonMessage = Dict::Format('UI:LoggedAsMessage+Admin', $sUserName); } else { $sLogonMessage = Dict::Format('UI:LoggedAsMessage', $sUserName); } $sLogOffBtn = Dict::S('UI:Button:Logoff'); $sSearchBtn = Dict::S('UI:Button:GlobalSearch'); echo "
{$sLogonMessage}  "; echo "
\n"; echo "\n"; echo "\n"; echo "
\n"; echo "
\n"; echo "
\n"; echo "\n"; // Display the menu echo "
\n"; echo "
\n"; echo $this->m_sMenu; echo "
\n"; echo "
\n"; // Display the page's content echo $this->s_content; */ // Add the captured output if (trim($s_captured_output) != "") { echo "
$s_captured_output
\n"; } echo $this->s_deferred_content; echo "
Please wait...
\n"; // jqModal Window 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])) { // Set the content of the tab $this->m_aTabs[$sTabContainer][$sTabLabel] = $sHtml; } else { // Append to the content of the tab $this->m_aTabs[$sTabContainer][$sTabLabel] .= $sHtml; } } public function SetCurrentTabContainer($sTabContainer = '') { $sPreviousTabContainer = $this->m_sCurrentTabContainer; $this->m_sCurrentTabContainer = $sTabContainer; return $sPreviousTabContainer; } public function SetCurrentTab($sTabLabel = '') { $sPreviousTab = $this->m_sCurrentTab; $this->m_sCurrentTab = $sTabLabel; return $sPreviousTab; } /** * Make the given tab the active one, as if it were clicked * DOES NOT WORK: apparently in the *old* version of jquery * that we are using this is not supported... TO DO upgrade * the whole jquery bundle... */ public function SelectTab($sTabContainer, $sTabLabel) { $container_index = 0; $tab_index = 0; foreach($this->m_aTabs as $sCurrentTabContainerName => $aTabs) { if ($sTabContainer == $sCurrentTabContainerName) { foreach($aTabs as $sCurrentTabLabel => $void) { if ($sCurrentTabLabel == $sTabLabel) { break; } $tab_index++; } break; } $container_index++; } $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)); } public function GetStartCollapsibleSection($sSectionLabel, $bOpen = false) { $sHtml = ''; static $iSectionId = 0; $sImgStyle = $bOpen ? ' open' : ''; $sHtml .= "$sSectionLabel
\n"; $sStyle = $bOpen ? '' : 'style="display:none" '; $sHtml .= "
"; $this->add_ready_script("\$(\"#LnkCollapse_$iSectionId\").click(function() {\$(\"#Collapse_$iSectionId\").slideToggle('normal'); $(\"#LnkCollapse_$iSectionId\").toggleClass('open');});"); //$this->add_ready_script("$('#LnkCollapse_$iSectionId').hide();"); $iSectionId++; return $sHtml; } public function EndCollapsibleSection() { $this->add($this->GetEndCollapsibleSection()); } public function GetEndCollapsibleSection() { 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 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++; } */ } ?>