itopwebpage.class.inc.php 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  1. <?php
  2. // Copyright (C) 2010-2012 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Class iTopWebPage
  20. *
  21. * @copyright Copyright (C) 2010-2012 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  23. */
  24. require_once(APPROOT."/application/nicewebpage.class.inc.php");
  25. require_once(APPROOT."/application/applicationcontext.class.inc.php");
  26. require_once(APPROOT."/application/user.preferences.class.inc.php");
  27. /**
  28. * Web page with some associated CSS and scripts (jquery) for a fancier display
  29. */
  30. class iTopWebPage extends NiceWebPage
  31. {
  32. private $m_sMenu;
  33. // private $m_currentOrganization;
  34. private $m_aTabs;
  35. private $m_sCurrentTabContainer;
  36. private $m_sCurrentTab;
  37. private $m_sMessage;
  38. private $m_sInitScript;
  39. public function __construct($sTitle)
  40. {
  41. parent::__construct($sTitle);
  42. ApplicationContext::SetUrlMakerClass('iTopStandardURLMaker');
  43. $this->m_sCurrentTabContainer = '';
  44. $this->m_sCurrentTab = '';
  45. $this->m_aTabs = array();
  46. $this->m_sMenu = "";
  47. $this->m_sMessage = '';
  48. $this->SetRootUrl(utils::GetAbsoluteUrlAppRoot());
  49. $this->add_header("Content-type: text/html; charset=utf-8");
  50. $this->add_header("Cache-control: no-cache");
  51. $this->add_linked_stylesheet("../css/jquery.treeview.css");
  52. $this->add_linked_stylesheet("../css/jquery.autocomplete.css");
  53. $this->add_linked_stylesheet("../css/fg.menu.css");
  54. $this->add_linked_stylesheet("../css/jquery.multiselect.css");
  55. $this->add_linked_script('../js/jquery.layout.min.js');
  56. $this->add_linked_script('../js/jquery.ba-bbq.min.js');
  57. $this->add_linked_script("../js/jquery.treeview.js");
  58. $this->add_linked_script("../js/jquery.autocomplete.js");
  59. $this->add_linked_script("../js/date.js");
  60. $this->add_linked_script("../js/jquery.blockUI.js");
  61. $this->add_linked_script("../js/utils.js");
  62. $this->add_linked_script("../js/swfobject.js");
  63. $this->add_linked_script("../js/ckeditor/ckeditor.js");
  64. $this->add_linked_script("../js/ckeditor/adapters/jquery.js");
  65. $this->add_linked_script("../js/jquery.qtip-1.0.min.js");
  66. $this->add_linked_script('../js/property_field.js');
  67. $this->add_linked_script('../js/fg.menu.js');
  68. $this->add_linked_script('../js/icon_select.js');
  69. $this->add_linked_script('../js/raphael-min.js');
  70. $this->add_linked_script('../js/g.raphael.js');
  71. $this->add_linked_script('../js/g.pie.js');
  72. $this->add_linked_script('../js/g.dot.js');
  73. $this->add_linked_script('../js/charts.js');
  74. $this->add_linked_script('../js/jquery.multiselect.min.js');
  75. $this->add_linked_script('../js/ajaxfileupload.js');
  76. $sSearchAny = addslashes(Dict::S('UI:SearchValue:Any'));
  77. $sSearchNbSelected = addslashes(Dict::S('UI:SearchValue:NbSelected'));
  78. $this->add_dict_entry('UI:FillAllMandatoryFields');
  79. $bForceMenuPane = utils::ReadParam('force_menu_pane', null);
  80. $sInitClosed = '';
  81. if (($bForceMenuPane !== null) && ($bForceMenuPane == 0))
  82. {
  83. $sInitClosed = 'initClosed: true,';
  84. }
  85. $this->m_sInitScript =
  86. <<< EOF
  87. try
  88. {
  89. var myLayout; // a var is required because this page utilizes: myLayout.allowOverflow() method
  90. // Layout
  91. paneSize = GetUserPreference('menu_size', 300)
  92. myLayout = $('body').layout({
  93. west : {
  94. $sInitClosed minSize: 200, size: paneSize, spacing_open: 16, spacing_close: 16, slideTrigger_open: "mouseover", hideTogglerOnSlide: true, enableCursorHotkey: false,
  95. onclose_end: function(name, elt, state, options, layout)
  96. {
  97. if (state.isSliding == false)
  98. {
  99. SetUserPreference('menu_pane', 'closed', true);
  100. }
  101. },
  102. onresize_end: function(name, elt, state, options, layout)
  103. {
  104. if (state.isSliding == false)
  105. {
  106. SetUserPreference('menu_size', state.size, true);
  107. }
  108. },
  109. onopen_end: function(name, elt, state, options, layout)
  110. {
  111. if (state.isSliding == false)
  112. {
  113. SetUserPreference('menu_pane', 'open', true);
  114. }
  115. }
  116. },
  117. center: {
  118. onresize_end: function(name, elt, state, options, layout)
  119. {
  120. $('.v-resizable').each( function() {
  121. var fixedWidth = $(this).parent().innerWidth() - 6;
  122. $(this).width(fixedWidth);
  123. // Make sure it cannot be resized horizontally
  124. $(this).resizable('options', { minWidth: fixedWidth, maxWidth: fixedWidth });
  125. // Now adjust all the child 'items'
  126. var innerWidth = $(this).innerWidth() - 10;
  127. $(this).find('.item').width(innerWidth);
  128. });
  129. }
  130. }
  131. });
  132. myLayout.addPinBtn( "#tPinMenu", "west" );
  133. //myLayout.open( "west" );
  134. $('.ui-layout-resizer-west .ui-layout-toggler').css({background: 'transparent'});
  135. if (GetUserPreference('menu_pane', 'open') == 'closed')
  136. {
  137. myLayout.close('west');
  138. }
  139. $('#left-pane').layout({ resizable: false, spacing_open: 0, south: { size: 94 }, enableCursorHotkey: false });
  140. // Accordion Menu
  141. $("#accordion").accordion({ header: "h3", navigation: true, autoHeight: false, collapsible: false, icons: false }); // collapsible will be enabled once the item will be selected
  142. // Tabs, using JQuery BBQ to store the history
  143. // The "tab widgets" to handle.
  144. var tabs = $('div[id^=tabbedContent]');
  145. // This selector will be reused when selecting actual tab widget A elements.
  146. var tab_a_selector = 'ul.ui-tabs-nav a';
  147. // Enable tabs on all tab widgets. The `event` property must be overridden so
  148. // that the tabs aren't changed on click, and any custom event name can be
  149. // specified. Note that if you define a callback for the 'select' event, it
  150. // will be executed for the selected tab whenever the hash changes.
  151. tabs.tabs({ event: 'change', 'show': function(event, ui) {
  152. $('.resizable', ui.panel).resizable(); // Make resizable everything that claims to be resizable !
  153. }
  154. });
  155. $('.multiselect').multiselect({header: false, noneSelectedText: '$sSearchAny', selectedList: 1, selectedText:'$sSearchNbSelected'});
  156. $('.resizable').filter(':visible').resizable();
  157. }
  158. catch(err)
  159. {
  160. // Do something with the error !
  161. alert(err);
  162. }
  163. EOF
  164. ;
  165. $this->add_ready_script(
  166. <<< EOF
  167. // Adjust initial size
  168. $('.v-resizable').each( function()
  169. {
  170. var parent_id = $(this).parent().id;
  171. // Restore the saved height
  172. var iHeight = GetUserPreference(parent_id+'_'+this.id+'_height', undefined);
  173. if (iHeight != undefined)
  174. {
  175. $(this).height(parseInt(iHeight, 10)); // Parse in base 10 !);
  176. }
  177. // Adjust the child 'item''s height and width to fit
  178. var container = $(this);
  179. var fixedWidth = container.parent().innerWidth() - 6;
  180. // Set the width to fit the parent
  181. $(this).width(fixedWidth);
  182. var headerHeight = $(this).find('.drag_handle').height();
  183. // Now adjust the width and height of the child 'item'
  184. container.find('.item').height(container.innerHeight() - headerHeight - 12).width(fixedWidth - 10);
  185. }
  186. );
  187. // Make resizable, vertically only everything that claims to be v-resizable !
  188. $('.v-resizable').resizable( { handles: 's', minHeight: $(this).find('.drag_handle').height(), minWidth: $(this).parent().innerWidth() - 6, maxWidth: $(this).parent().innerWidth() - 6, stop: function()
  189. {
  190. // Adjust the content
  191. var container = $(this);
  192. var headerHeight = $(this).find('.drag_handle').height();
  193. container.find('.item').height(container.innerHeight() - headerHeight - 12);//.width(container.innerWidth());
  194. var parent_id = $(this).parent().id;
  195. SetUserPreference(parent_id+'_'+this.id+'_height', $(this).height(), true); // true => persistent
  196. }
  197. } );
  198. // Tabs, using JQuery BBQ to store the history
  199. // The "tab widgets" to handle.
  200. var tabs = $('div[id^=tabbedContent]');
  201. // This selector will be reused when selecting actual tab widget A elements.
  202. var tab_a_selector = 'ul.ui-tabs-nav a';
  203. // Define our own click handler for the tabs, overriding the default.
  204. tabs.find( tab_a_selector ).click(function()
  205. {
  206. var state = {};
  207. // Get the id of this tab widget.
  208. var id = $(this).closest( 'div[id^=tabbedContent]' ).attr( 'id' );
  209. // Get the index of this tab.
  210. var idx = $(this).parent().prevAll().length;
  211. // Set the state!
  212. state[ id ] = idx;
  213. $.bbq.pushState( state );
  214. });
  215. // Bind an event to window.onhashchange that, when the history state changes,
  216. // iterates over all tab widgets, changing the current tab as necessary.
  217. $(window).bind( 'hashchange', function(e)
  218. {
  219. // Iterate over all tab widgets.
  220. tabs.each(function()
  221. {
  222. // Get the index for this tab widget from the hash, based on the
  223. // appropriate id property. In jQuery 1.4, you should use e.getState()
  224. // instead of $.bbq.getState(). The second, 'true' argument coerces the
  225. // string value to a number.
  226. var idx = $.bbq.getState( this.id, true ) || 0;
  227. // Select the appropriate tab for this tab widget by triggering the custom
  228. // event specified in the .tabs() init above (you could keep track of what
  229. // tab each widget is on using .data, and only select a tab if it has
  230. // changed).
  231. $(this).find( tab_a_selector ).eq( idx ).triggerHandler( 'change' );
  232. });
  233. // Iterate over all truncated lists to find whether they are expanded or not
  234. $('a.truncated').each(function()
  235. {
  236. var state = $.bbq.getState( this.id, true ) || 'close';
  237. if (state == 'open')
  238. {
  239. $(this).trigger('open');
  240. }
  241. else
  242. {
  243. $(this).trigger('close');
  244. }
  245. });
  246. });
  247. // Shortcut menu actions
  248. $('.actions_button a').click( function() {
  249. aMatches = /#(.*)$/.exec(window.location.href);
  250. if (aMatches != null)
  251. {
  252. currentHash = aMatches[1];
  253. if ( /#(.*)$/.test(this.href))
  254. {
  255. this.href = this.href.replace(/#(.*)$/, '#'+currentHash);
  256. }
  257. }
  258. });
  259. // End of Tabs handling
  260. $(".date-pick").datepicker({
  261. showOn: 'button',
  262. buttonImage: '../images/calendar.png',
  263. buttonImageOnly: true,
  264. dateFormat: 'yy-mm-dd',
  265. constrainInput: false,
  266. changeMonth: true,
  267. changeYear: true
  268. });
  269. $(".datetime-pick").datepicker({
  270. showOn: 'button',
  271. buttonImage: '../images/calendar.png',
  272. buttonImageOnly: true,
  273. dateFormat: 'yy-mm-dd 00:00:00',
  274. constrainInput: false,
  275. changeMonth: true,
  276. changeYear: true
  277. });
  278. // Make sortable, everything that claims to be sortable
  279. $('.sortable').sortable( {axis: 'y', cursor: 'move', handle: '.drag_handle', stop: function()
  280. {
  281. if ($(this).hasClass('persistent'))
  282. {
  283. // remember the sort order for next time the page is loaded...
  284. sSerialized = $(this).sortable('serialize', {key: 'menu'});
  285. var sTemp = sSerialized.replace(/menu=/g, '');
  286. SetUserPreference(this.id+'_order', sTemp.replace(/&/g, ','), true); // true => persistent !
  287. }
  288. }
  289. });
  290. docWidth = $(document).width();
  291. $('#ModalDlg').dialog({ autoOpen: false, modal: true, width: 0.8*docWidth }); // JQuery UI dialogs
  292. ShowDebug();
  293. $('#logOffBtn>ul').popupmenu();
  294. $('.caselog_header').click( function () { $(this).toggleClass('open').next('.caselog_entry').toggle(); });
  295. EOF
  296. );
  297. $sUserPrefs = appUserPreferences::GetAsJSON();
  298. $this->add_script(
  299. <<<EOF
  300. // // for JQuery history
  301. // function history_callback(hash)
  302. // {
  303. // // do stuff that loads page content based on hash variable
  304. // var aMatches = /^tab_(.*)$/.exec(hash);
  305. // if (aMatches != null)
  306. // {
  307. // var tab = $('#'+hash);
  308. // tab.parents('div[id^=tabbedContent]:first').tabs('select', aMatches[1]);
  309. // }
  310. // }
  311. function goBack()
  312. {
  313. window.history.back();
  314. }
  315. function BackToDetails(sClass, id, sDefaultUrl)
  316. {
  317. window.bInCancel = true;
  318. if (id > 0)
  319. {
  320. window.location.href = AddAppContext(GetAbsoluteUrlAppRoot()+'pages/UI.php?operation=details&class='+sClass+'&id='+id);
  321. }
  322. else
  323. {
  324. window.location.href = sDefaultUrl; // Already contains the context...
  325. }
  326. }
  327. function BackToList(sClass)
  328. {
  329. window.location.href = AddAppContext(GetAbsoluteUrlAppRoot()+'pages/UI.php?operation=search_oql&oql_class='+sClass+'&oql_clause=WHERE id=0');
  330. }
  331. function ShowDebug()
  332. {
  333. if ($('#rawOutput > div').html() != '')
  334. {
  335. $('#rawOutput').dialog( {autoOpen: true, modal:false});
  336. }
  337. }
  338. var oUserPreferences = $sUserPrefs;
  339. // For disabling the CKEditor at init time when the corresponding textarea is disabled !
  340. CKEDITOR.plugins.add( 'disabler',
  341. {
  342. init : function( editor )
  343. {
  344. editor.on( 'instanceReady', function(e)
  345. {
  346. e.removeListener();
  347. $('#'+ editor.name).trigger('update');
  348. });
  349. }
  350. });
  351. EOF
  352. );
  353. }
  354. public function AddToMenu($sHtml)
  355. {
  356. $this->m_sMenu .= $sHtml;
  357. }
  358. public function GetSiloSelectionForm()
  359. {
  360. // List of visible Organizations
  361. $iCount = 0;
  362. $oSet = null;
  363. if (MetaModel::IsValidClass('Organization'))
  364. {
  365. // Display the list of *favorite* organizations... but keeping in mind what is the real number of organizations
  366. $aFavoriteOrgs = appUserPreferences::GetPref('favorite_orgs', null);
  367. $oSearchFilter = new DBObjectSearch('Organization');
  368. $oSearchFilter->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', true);
  369. $oSet = new CMDBObjectSet($oSearchFilter);
  370. $iCount = $oSet->Count(); // total number of existing Orgs
  371. // Now get the list of Orgs to be displayed in the menu
  372. $oSearchFilter = DBObjectSearch::FromOQL(ApplicationMenu::GetFavoriteSiloQuery());
  373. $oSearchFilter->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', true);
  374. if (!empty($aFavoriteOrgs))
  375. {
  376. $oSearchFilter->AddCondition('id', $aFavoriteOrgs, 'IN');
  377. }
  378. $oSet = new CMDBObjectSet($oSearchFilter); // List of favorite orgs
  379. }
  380. switch($iCount)
  381. {
  382. case 0:
  383. // No such dimension/silo => nothing to select
  384. $sHtml = '<div id="SiloSelection"><!-- nothing to select --></div>';
  385. break;
  386. case 1:
  387. // Only one possible choice... no selection, but display the value
  388. $oOrg = $oSet->Fetch();
  389. $sHtml = '<div id="SiloSelection">'.$oOrg->GetName().'</div>';
  390. $sHtml .= '';
  391. break;
  392. default:
  393. $sHtml = '';
  394. $oAppContext = new ApplicationContext();
  395. $iCurrentOrganization = $oAppContext->GetCurrentValue('org_id');
  396. $sHtml = '<div id="SiloSelection">';
  397. $sHtml .= '<form style="display:inline" action="'.utils::GetAbsoluteUrlAppRoot().'pages/UI.php">'; //<select class="org_combo" name="c[org_id]" title="Pick an organization" onChange="this.form.submit();">';
  398. $sFavoriteOrgs = '';
  399. $oWidget = new UIExtKeyWidget('Organization', 'org_id', '', true /* search mode */);
  400. $sHtml .= $oWidget->Display($this, 50, false, '', $oSet, $iCurrentOrganization, 'org_id', false, 'c[org_id]', '',
  401. array('iFieldSize' => 20, 'iMinChars' => MetaModel::GetConfig()->Get('min_autocomplete_chars'), 'sDefaultValue' => Dict::S('UI:AllOrganizations')),
  402. null, 'select', false /* bSearchMultiple */);
  403. $this->add_ready_script('$("#org_id").bind("extkeychange", function() { $("#SiloSelection form").submit(); } )');
  404. $this->add_ready_script("$('#label_org_id').click( function() { $(this).val(''); $('#org_id').val(''); return true; } );\n");
  405. // Add other dimensions/context information to this form
  406. $oAppContext->Reset('org_id'); // org_id is handled above and we want to be able to change it here !
  407. $oAppContext->Reset('menu'); // don't pass the menu, since a menu may expect more parameters
  408. $sHtml .= $oAppContext->GetForForm(); // Pass what remains, if anything...
  409. $sHtml .= '</form>';
  410. $sHtml .= '</div>';
  411. }
  412. return $sHtml;
  413. }
  414. public function DisplayMenu()
  415. {
  416. // Display the menu
  417. $oAppContext = new ApplicationContext();
  418. $iAccordionIndex = 0;
  419. ApplicationMenu::DisplayMenu($this, $oAppContext->GetAsHash());
  420. }
  421. /**
  422. * Outputs (via some echo) the complete HTML page by assembling all its elements
  423. */
  424. public function output()
  425. {
  426. $sAbsURLAppRoot = addslashes($this->m_sRootUrl);
  427. //$this->set_base($this->m_sRootUrl.'pages/');
  428. $sForm = $this->GetSiloSelectionForm();
  429. $this->DisplayMenu(); // Compute the menu
  430. // Call the extensions to add content to the page, so that they can also add styles or scripts
  431. $sBannerExtraHtml = '';
  432. foreach (MetaModel::EnumPlugins('iPageUIExtension') as $oExtensionInstance)
  433. {
  434. $sBannerExtraHtml .= $oExtensionInstance->GetBannerHtml($this);
  435. }
  436. $sNorthPane = '';
  437. foreach (MetaModel::EnumPlugins('iPageUIExtension') as $oExtensionInstance)
  438. {
  439. $sNorthPane .= $oExtensionInstance->GetNorthPaneHtml($this);
  440. }
  441. $sSouthPane = '';
  442. foreach (MetaModel::EnumPlugins('iPageUIExtension') as $oExtensionInstance)
  443. {
  444. $sSouthPane .= $oExtensionInstance->GetSouthPaneHtml($this);
  445. }
  446. // Put here the 'ready scripts' that must be executed after all others
  447. $this->add_ready_script(
  448. <<<EOF
  449. // Since the event is only triggered when the hash changes, we need to trigger
  450. // the event now, to handle the hash the page may have loaded with.
  451. $(window).trigger( 'hashchange' );
  452. // Some table are sort-able, some are not, let's fix this
  453. $('table.listResults').each( function() { FixTableSorter($(this)); } );
  454. EOF
  455. );
  456. if ($this->GetOutputFormat() == 'html')
  457. {
  458. foreach($this->a_headers as $s_header)
  459. {
  460. header($s_header);
  461. }
  462. }
  463. $s_captured_output = ob_get_contents();
  464. ob_end_clean();
  465. $sHtml = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
  466. $sHtml .= "<html>\n";
  467. $sHtml .= "<head>\n";
  468. // Make sure that Internet Explorer renders the page using its latest/highest/greatest standards !
  469. $sHtml .= "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n";
  470. $sHtml .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
  471. $sHtml .= "<title>".htmlentities($this->s_title, ENT_QUOTES, 'UTF-8')."</title>\n";
  472. $sHtml .= $this->get_base_tag();
  473. // Stylesheets MUST be loaded before any scripts otherwise
  474. // jQuery scripts may face some spurious problems (like failing on a 'reload')
  475. foreach($this->a_linked_stylesheets as $a_stylesheet)
  476. {
  477. if ($a_stylesheet['condition'] != "")
  478. {
  479. $sHtml .= "<!--[if {$a_stylesheet['condition']}]>\n";
  480. }
  481. $sHtml .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$a_stylesheet['link']}\" />\n";
  482. if ($a_stylesheet['condition'] != "")
  483. {
  484. $sHtml .= "<![endif]-->\n";
  485. }
  486. }
  487. // special stylesheet for printing, hides the navigation gadgets
  488. $sHtml .= "<link rel=\"stylesheet\" media=\"print\" type=\"text/css\" href=\"../css/print.css\" />\n";
  489. if ($this->GetOutputFormat() == 'html')
  490. {
  491. foreach($this->a_linked_scripts as $s_script)
  492. {
  493. // Make sure that the URL to the script contains the application's version number
  494. // so that the new script do NOT get reloaded from the cache when the application is upgraded
  495. if (strpos($s_script, '?') === false)
  496. {
  497. $s_script .= "?itopversion=".ITOP_VERSION;
  498. }
  499. else
  500. {
  501. $s_script .= "&itopversion=".ITOP_VERSION;
  502. }
  503. $sHtml .= "<script type=\"text/javascript\" src=\"$s_script\"></script>\n";
  504. }
  505. $this->add_script("\$(document).ready(function() {\n{$this->m_sInitScript};\nwindow.setTimeout('onDelayedReady()',10)\n});");
  506. if (count($this->m_aReadyScripts)>0)
  507. {
  508. $this->add_script("\nonDelayedReady = function() {\n".implode("\n", $this->m_aReadyScripts)."\n}\n");
  509. }
  510. if (count($this->a_scripts)>0)
  511. {
  512. $sHtml .= "<script type=\"text/javascript\">\n";
  513. foreach($this->a_scripts as $s_script)
  514. {
  515. $sHtml .= "$s_script\n";
  516. }
  517. $sHtml .= "</script>\n";
  518. }
  519. $this->output_dict_entries();
  520. }
  521. if (count($this->a_styles)>0)
  522. {
  523. $sHtml .= "<style>\n";
  524. foreach($this->a_styles as $s_style)
  525. {
  526. $sHtml .= "$s_style\n";
  527. }
  528. $sHtml .= "</style>\n";
  529. }
  530. $sHtml .= "<link rel=\"search\" type=\"application/opensearchdescription+xml\" title=\"iTop\" href=\"".utils::GetAbsoluteUrlAppRoot()."pages/opensearch.xml.php\" />\n";
  531. $sHtml .= "<link rel=\"shortcut icon\" href=\"".utils::GetAbsoluteUrlAppRoot()."images/favicon.ico\" />\n";
  532. $sHtml .= "</head>\n";
  533. $sHtml .= "<body>\n";
  534. // Render the revision number
  535. if (ITOP_REVISION == '$WCREV$')
  536. {
  537. // This is NOT a version built using the buil system, just display the main version
  538. $sVersionString = Dict::Format('UI:iTopVersion:Short', ITOP_VERSION);
  539. }
  540. else
  541. {
  542. // This is a build made from SVN, let display the full information
  543. $sVersionString = Dict::Format('UI:iTopVersion:Long', ITOP_VERSION, ITOP_REVISION, ITOP_BUILD_DATE);
  544. }
  545. // Render the text of the global search form
  546. $sText = htmlentities(utils::ReadParam('text', '', false, 'raw_data'), ENT_QUOTES, 'UTF-8');
  547. $sOnClick = "";
  548. if (empty($sText))
  549. {
  550. // if no search text is supplied then
  551. // 1) the search text is filled with "your search"
  552. // 2) clicking on it will erase it
  553. $sText = Dict::S("UI:YourSearch");
  554. $sOnClick = " onclick=\"this.value='';this.onclick=null;\"";
  555. }
  556. // Render the tabs in the page (if any)
  557. foreach($this->m_aTabs as $sTabContainerName => $m_aTabs)
  558. {
  559. $sTabs = '';
  560. $container_index = 0;
  561. if (count($m_aTabs) > 0)
  562. {
  563. $sTabs = "<!-- tabs -->\n<div id=\"tabbedContent_{$container_index}\" class=\"light\">\n";
  564. $sTabs .= "<ul>\n";
  565. // Display the unordered list that will be rendered as the tabs
  566. $i = 0;
  567. foreach($m_aTabs as $sTabName => $sTabContent)
  568. {
  569. $sTabs .= "<li><a href=\"#tab_$i\" class=\"tab\"><span>".htmlentities($sTabName, ENT_QUOTES, 'UTF-8')."</span></a></li>\n";
  570. $i++;
  571. }
  572. $sTabs .= "</ul>\n";
  573. // Now add the content of the tabs themselves
  574. $i = 0;
  575. foreach($m_aTabs as $sTabName => $sTabContent)
  576. {
  577. $sTabs .= "<div id=\"tab_$i\">".$sTabContent."</div>\n";
  578. $i++;
  579. }
  580. $sTabs .= "</div>\n<!-- end of tabs-->\n";
  581. }
  582. $this->s_content = str_replace("\$Tabs:$sTabContainerName\$", $sTabs, $this->s_content);
  583. $container_index++;
  584. }
  585. if ($this->GetOutputFormat() == 'html')
  586. {
  587. $oAppContext = new ApplicationContext();
  588. $sUserName = UserRights::GetUser();
  589. $sIsAdmin = UserRights::IsAdministrator() ? '(Administrator)' : '';
  590. if (UserRights::IsAdministrator())
  591. {
  592. $sLogonMessage = Dict::Format('UI:LoggedAsMessage+Admin', $sUserName);
  593. }
  594. else
  595. {
  596. $sLogonMessage = Dict::Format('UI:LoggedAsMessage', $sUserName);
  597. }
  598. $sLogOffMenu = "<span id=\"logOffBtn\"><ul><li><img src=\"../images/onOffBtn.png\"><ul>";
  599. $sLogOffMenu .= "<li><span>$sLogonMessage</span></li>\n";
  600. $aActions = array();
  601. $oPrefs = new URLPopupMenuItem('UI:Preferences', Dict::S('UI:Preferences'), utils::GetAbsoluteUrlAppRoot()."pages/preferences.php?".$oAppContext->GetForLink());
  602. $aActions[$oPrefs->GetUID()] = $oPrefs->GetMenuItem();
  603. if (utils::CanLogOff())
  604. {
  605. $oLogOff = new URLPopupMenuItem('UI:LogOffMenu', Dict::S('UI:LogOffMenu'), utils::GetAbsoluteUrlAppRoot().'pages/logoff.php');
  606. $aActions[$oLogOff->GetUID()] = $oLogOff->GetMenuItem();
  607. }
  608. if (UserRights::CanChangePassword())
  609. {
  610. $oChangePwd = new URLPopupMenuItem('UI:ChangePwdMenu', Dict::S('UI:ChangePwdMenu'), utils::GetAbsoluteUrlAppRoot().'pages/UI.php?loginop=change_pwd');
  611. $aActions[$oChangePwd->GetUID()] = $oChangePwd->GetMenuItem();
  612. }
  613. utils::GetPopupMenuItems($this, iPopupMenuExtension::MENU_USER_ACTIONS, null, $aActions);
  614. $sLogOffMenu .= $this->RenderPopupMenuItems($aActions);
  615. $sRestrictions = '';
  616. if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE))
  617. {
  618. if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE))
  619. {
  620. $sRestrictions = Dict::S('UI:AccessRO-All');
  621. }
  622. }
  623. elseif (!MetaModel::DBHasAccess(ACCESS_USER_WRITE))
  624. {
  625. $sRestrictions = Dict::S('UI:AccessRO-Users');
  626. }
  627. $sApplicationBanner = '';
  628. if (strlen($sRestrictions) > 0)
  629. {
  630. $sAdminMessage = trim(MetaModel::GetConfig()->Get('access_message'));
  631. $sApplicationBanner .= '<div id="admin-banner">';
  632. $sApplicationBanner .= '<img src="../images/locked.png" style="vertical-align:middle;">';
  633. $sApplicationBanner .= '&nbsp;<b>'.$sRestrictions.'</b>';
  634. if (strlen($sAdminMessage) > 0)
  635. {
  636. $sApplicationBanner .= '&nbsp;<b>'.$sAdminMessage.'</b>';
  637. }
  638. $sApplicationBanner .= '</div>';
  639. }
  640. if(strlen($this->m_sMessage))
  641. {
  642. $sApplicationBanner .= '<div id="admin-banner"><span style="padding:5px;">'.$this->m_sMessage.'<span></div>';
  643. }
  644. $sEnvironment = utils::GetCurrentEnvironment();
  645. $sBackButton = utils::GetEnvironmentBackButton();
  646. if($sEnvironment != 'production')
  647. {
  648. $sEnvLabel = trim(MetaModel::GetConfig()->Get('app_env_label'));
  649. if (strlen($sEnvLabel) == 0)
  650. {
  651. $sEnvLabel = $sEnvironment;
  652. }
  653. $sApplicationBanner .= '<div id="admin-banner"><span style="padding:5px;">'.Dict::Format('UI:ApplicationEnvironment', $sEnvLabel).$sBackButton.'<span></div>';
  654. }
  655. $sApplicationBanner .= $sBannerExtraHtml;
  656. if (!empty($sNorthPane))
  657. {
  658. $sNorthPane = '<div id="bottom-pane" class="ui-layout-north">'.$sNorthPane.'</div>';
  659. }
  660. if (!empty($sSouthPane))
  661. {
  662. $sSouthPane = '<div id="bottom-pane" class="ui-layout-south">'.$sSouthPane.'</div>';
  663. }
  664. $sIconUrl = Utils::GetConfig()->Get('app_icon_url');
  665. $sOnlineHelpUrl = MetaModel::GetConfig()->Get('online_help');
  666. //$sLogOffMenu = "<span id=\"logOffBtn\" style=\"height:55px;padding:0;margin:0;\"><img src=\"../images/onOffBtn.png\"></span>";
  667. $sHtml .= $sNorthPane;
  668. $sHtml .= '<div id="left-pane" class="ui-layout-west">';
  669. $sHtml .= '<!-- Beginning of the left pane -->';
  670. $sHtml .= ' <div class="ui-layout-north">';
  671. $sHtml .= ' <div id="header-logo">';
  672. $sHtml .= ' <div id="top-left"></div><div id="logo"><a href="'.htmlentities($sIconUrl, ENT_QUOTES, 'UTF-8').'"><img src="../images/itop-logo.png" title="'.htmlentities($sVersionString, ENT_QUOTES, 'UTF-8').'" style="border:0; margin-top:16px; margin-right:40px;"/></a></div>';
  673. $sHtml .= ' </div>';
  674. $sHtml .= ' <div class="header-menu">';
  675. $sHtml .= ' <div class="icon ui-state-default ui-corner-all"><span id="tPinMenu" class="ui-icon ui-icon-pin-w">pin</span></div>';
  676. $sHtml .= ' <div style="text-align:center;">'.self::FilterXSS($sForm).'</div>';
  677. $sHtml .= ' </div>';
  678. $sHtml .= ' </div>';
  679. $sHtml .= ' <div id="menu" class="ui-layout-center">';
  680. $sHtml .= ' <div id="inner_menu">';
  681. $sHtml .= ' <div id="accordion">';
  682. $sHtml .= self::FilterXSS($this->m_sMenu);
  683. $sHtml .= ' <!-- Beginning of the accordion menu -->';
  684. $sHtml .= ' <!-- End of the accordion menu-->';
  685. $sHtml .= ' </div>';
  686. $sHtml .= ' </div> <!-- /inner menu -->';
  687. $sHtml .= ' </div> <!-- /menu -->';
  688. $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>';
  689. $sHtml .= '<!-- End of the left pane -->';
  690. $sHtml .= '</div>';
  691. $sHtml .= '<div class="ui-layout-center">';
  692. $sHtml .= ' <div id="top-bar" style="width:100%">';
  693. $sHtml .= self::FilterXSS($sApplicationBanner);
  694. $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>';
  695. $sHtml .= '<td><input type="image" src="../images/searchBtn.png"/></a></td>';
  696. $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>';
  697. $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>';
  698. //echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="hidden" name="operation" value="full_text"/></td></tr></table></form></div>';
  699. $sHtml .= ' </div>';
  700. $sHtml .= ' <div class="ui-layout-content">';
  701. $sHtml .= ' <!-- Beginning of page content -->';
  702. $sHtml .= self::FilterXSS($this->s_content);
  703. $sHtml .= ' <!-- End of page content -->';
  704. $sHtml .= ' </div>';
  705. $sHtml .= '</div>';
  706. $sHtml .= $sSouthPane;
  707. // Add the captured output
  708. if (trim($s_captured_output) != "")
  709. {
  710. $sHtml .= "<div id=\"rawOutput\" title=\"Debug Output\"><div style=\"height:500px; overflow-y:auto;\">".self::FilterXSS($s_captured_output)."</div></div>\n";
  711. }
  712. $sHtml .= "<div id=\"at_the_end\">".self::FilterXSS($this->s_deferred_content)."</div>";
  713. $sHtml .= "<div style=\"display:none\" title=\"ex2\" id=\"ex2\">Please wait...</div>\n"; // jqModal Window
  714. $sHtml .= "<div style=\"display:none\" title=\"dialog\" id=\"ModalDlg\"></div>";
  715. $sHtml .= "<div style=\"display:none\" id=\"ajax_content\"></div>";
  716. }
  717. else
  718. {
  719. $sHtml .= self::FilterXSS($this->s_content);
  720. }
  721. $sHtml .= "</body>\n";
  722. $sHtml .= "</html>\n";
  723. if ($this->GetOutputFormat() == 'html')
  724. {
  725. echo $sHtml;
  726. }
  727. else if ($this->GetOutputFormat() == 'pdf' && $this->IsOutputFormatAvailable('pdf') )
  728. {
  729. require_once(APPROOT.'lib/MPDF/mpdf.php');
  730. $oMPDF = new mPDF('c');
  731. $oMPDF->mirroMargins = false;
  732. if ($this->a_base['href'] != '')
  733. {
  734. $oMPDF->setBasePath($this->a_base['href']); // Seems that the <BASE> tag is not recognized by mPDF...
  735. }
  736. $oMPDF->showWatermarkText = true;
  737. if ($this->GetOutputOption('pdf', 'template_path'))
  738. {
  739. $oMPDF->setImportUse(); // Allow templates
  740. $oMPDF->SetDocTemplate ($this->GetOutputOption('pdf', 'template_path'), 1);
  741. }
  742. $oMPDF->WriteHTML($sHtml);
  743. $sOutputName = $this->s_title.'.pdf';
  744. if ($this->GetOutputOption('pdf', 'output_name'))
  745. {
  746. $sOutputName = $this->GetOutputOption('pdf', 'output_name');
  747. }
  748. $oMPDF->Output($sOutputName, 'I');
  749. }
  750. MetaModel::RecordQueryTrace();
  751. }
  752. public function AddTabContainer($sTabContainer)
  753. {
  754. $this->m_aTabs[$sTabContainer] = array();
  755. $this->add("\$Tabs:$sTabContainer\$");
  756. }
  757. public function AddToTab($sTabContainer, $sTabLabel, $sHtml)
  758. {
  759. if (!isset($this->m_aTabs[$sTabContainer][$sTabLabel]))
  760. {
  761. // Set the content of the tab
  762. $this->m_aTabs[$sTabContainer][$sTabLabel] = $sHtml;
  763. }
  764. else
  765. {
  766. // Append to the content of the tab
  767. $this->m_aTabs[$sTabContainer][$sTabLabel] .= $sHtml;
  768. }
  769. }
  770. public function SetCurrentTabContainer($sTabContainer = '')
  771. {
  772. $sPreviousTabContainer = $this->m_sCurrentTabContainer;
  773. $this->m_sCurrentTabContainer = $sTabContainer;
  774. return $sPreviousTabContainer;
  775. }
  776. public function SetCurrentTab($sTabLabel = '')
  777. {
  778. $sPreviousTab = $this->m_sCurrentTab;
  779. $this->m_sCurrentTab = $sTabLabel;
  780. return $sPreviousTab;
  781. }
  782. public function GetCurrentTab()
  783. {
  784. return $this->m_sCurrentTab;
  785. }
  786. public function RemoveTab($sTabLabel, $sTabContainer = null)
  787. {
  788. if ($sTabContainer == null)
  789. {
  790. $sTabContainer = $this->m_sCurrentTabContainer;
  791. }
  792. if (isset($this->m_aTabs[$sTabContainer][$sTabLabel]))
  793. {
  794. // Delete the content of the tab
  795. unset($this->m_aTabs[$sTabContainer][$sTabLabel]);
  796. // If we just removed the active tab, let's reset the active tab
  797. if (($this->m_sCurrentTabContainer == $sTabContainer) && ($this->m_sCurrentTab == $sTabLabel))
  798. {
  799. $this->m_sCurrentTab = '';
  800. }
  801. }
  802. }
  803. /**
  804. * Finds the tab whose title matches a given pattern
  805. * @return mixed The name of the tab as a string or false if not found
  806. */
  807. public function FindTab($sPattern, $sTabContainer = null)
  808. {
  809. $return = false;
  810. if ($sTabContainer == null)
  811. {
  812. $sTabContainer = $this->m_sCurrentTabContainer;
  813. }
  814. foreach($this->m_aTabs[$sTabContainer] as $sTabLabel => $void)
  815. {
  816. if (preg_match($sPattern, $sTabLabel))
  817. {
  818. $result = $sTabLabel;
  819. break;
  820. }
  821. }
  822. return $result;
  823. }
  824. /**
  825. * Make the given tab the active one, as if it were clicked
  826. * DOES NOT WORK: apparently in the *old* version of jquery
  827. * that we are using this is not supported... TO DO upgrade
  828. * the whole jquery bundle...
  829. */
  830. public function SelectTab($sTabContainer, $sTabLabel)
  831. {
  832. $container_index = 0;
  833. $tab_index = 0;
  834. foreach($this->m_aTabs as $sCurrentTabContainerName => $aTabs)
  835. {
  836. if ($sTabContainer == $sCurrentTabContainerName)
  837. {
  838. foreach($aTabs as $sCurrentTabLabel => $void)
  839. {
  840. if ($sCurrentTabLabel == $sTabLabel)
  841. {
  842. break;
  843. }
  844. $tab_index++;
  845. }
  846. break;
  847. }
  848. $container_index++;
  849. }
  850. $sSelector = '#tabbedContent_'.$container_index.' > ul';
  851. $this->add_ready_script("$('$sSelector').tabs('select', $tab_index);");
  852. }
  853. public function StartCollapsibleSection($sSectionLabel, $bOpen = false)
  854. {
  855. $this->add($this->GetStartCollapsibleSection($sSectionLabel, $bOpen));
  856. }
  857. public function GetStartCollapsibleSection($sSectionLabel, $bOpen = false)
  858. {
  859. $sHtml = '';
  860. static $iSectionId = 0;
  861. $sImgStyle = $bOpen ? ' open' : '';
  862. $sHtml .= "<a id=\"LnkCollapse_$iSectionId\" class=\"CollapsibleLabel{$sImgStyle}\" href=\"#\">$sSectionLabel</a></br>\n";
  863. $sStyle = $bOpen ? '' : 'style="display:none" ';
  864. $sHtml .= "<div id=\"Collapse_$iSectionId\" $sStyle>";
  865. $this->add_ready_script("\$(\"#LnkCollapse_$iSectionId\").click(function() {\$(\"#Collapse_$iSectionId\").slideToggle('normal'); $(\"#LnkCollapse_$iSectionId\").toggleClass('open');});");
  866. //$this->add_ready_script("$('#LnkCollapse_$iSectionId').hide();");
  867. $iSectionId++;
  868. return $sHtml;
  869. }
  870. public function EndCollapsibleSection()
  871. {
  872. $this->add($this->GetEndCollapsibleSection());
  873. }
  874. public function GetEndCollapsibleSection()
  875. {
  876. return "</div>";
  877. }
  878. public function add($sHtml)
  879. {
  880. if (!empty($this->m_sCurrentTabContainer) && !empty($this->m_sCurrentTab))
  881. {
  882. $this->AddToTab($this->m_sCurrentTabContainer, $this->m_sCurrentTab, $sHtml);
  883. }
  884. else
  885. {
  886. parent::add($sHtml);
  887. }
  888. }
  889. /**
  890. * Records the current state of the 'html' part of the page output
  891. * @return mixed The current state of the 'html' output
  892. */
  893. public function start_capture()
  894. {
  895. if (!empty($this->m_sCurrentTabContainer) && !empty($this->m_sCurrentTab))
  896. {
  897. $iOffset = isset($this->m_aTabs[$this->m_sCurrentTabContainer][$this->m_sCurrentTab]) ? strlen($this->m_aTabs[$this->m_sCurrentTabContainer][$this->m_sCurrentTab]): 0;
  898. return array('tc' => $this->m_sCurrentTabContainer, 'tab' => $this->m_sCurrentTab, 'offset' => $iOffset);
  899. }
  900. else
  901. {
  902. return parent::start_capture();
  903. }
  904. }
  905. /**
  906. * Returns the part of the html output that occurred since the call to start_capture
  907. * and removes this part from the current html output
  908. * @param $offset mixed The value returned by start_capture
  909. * @return string The part of the html output that was added since the call to start_capture
  910. */
  911. public function end_capture($offset)
  912. {
  913. if (is_array($offset))
  914. {
  915. if (isset($this->m_aTabs[$offset['tc']][$offset['tab']]))
  916. {
  917. $sCaptured = substr($this->m_aTabs[$offset['tc']][$offset['tab']], $offset['offset']);
  918. $this->m_aTabs[$offset['tc']][$offset['tab']] = substr($this->m_aTabs[$offset['tc']][$offset['tab']], 0, $offset['offset']);
  919. }
  920. else
  921. {
  922. $sCaptured = '';
  923. }
  924. }
  925. else
  926. {
  927. $sCaptured = parent::end_capture($offset);
  928. }
  929. return $sCaptured;
  930. }
  931. /**
  932. * Set the message to be displayed in the 'admin-banner' section at the top of the page
  933. */
  934. public function SetMessage($sMessage)
  935. {
  936. $this->m_sMessage = $sMessage;
  937. }
  938. }
  939. ?>