itopwebpage.class.inc.php 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  1. <?php
  2. // Copyright (C) 2010-2016 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-2016 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 implements iTabbedPage
  31. {
  32. private $m_sMenu;
  33. // private $m_currentOrganization;
  34. private $m_sMessage;
  35. private $m_sInitScript;
  36. protected $m_oTabs;
  37. protected $bBreadCrumbEnabled;
  38. protected $sBreadCrumbEntryId;
  39. protected $sBreadCrumbEntryLabel;
  40. protected $sBreadCrumbEntryDescription;
  41. protected $sBreadCrumbEntryUrl;
  42. protected $sBreadCrumbEntryIcon;
  43. public function __construct($sTitle, $bPrintable = false)
  44. {
  45. parent::__construct($sTitle, $bPrintable);
  46. $this->m_oTabs = new TabManager();
  47. ApplicationContext::SetUrlMakerClass('iTopStandardURLMaker');
  48. if ((count($_POST) == 0) || (array_key_exists('loginop', $_POST)))
  49. {
  50. // Create a breadcrumb entry for the current page, but get its title as late as possible (page title could be changed later)
  51. $this->bBreadCrumbEnabled = true;
  52. }
  53. else
  54. {
  55. $this->bBreadCrumbEnabled = false;
  56. }
  57. $this->m_sMenu = "";
  58. $this->m_sMessage = '';
  59. $this->SetRootUrl(utils::GetAbsoluteUrlAppRoot());
  60. $this->add_header("Content-type: text/html; charset=utf-8");
  61. $this->add_header("Cache-control: no-cache");
  62. $this->add_linked_stylesheet("../css/jquery.treeview.css");
  63. $this->add_linked_stylesheet("../css/jquery.autocomplete.css");
  64. $this->add_linked_stylesheet("../css/jquery-ui-timepicker-addon.css");
  65. $this->add_linked_stylesheet("../css/fg.menu.css");
  66. $this->add_linked_stylesheet("../css/jquery.multiselect.css");
  67. $this->add_linked_stylesheet("../css/magnific-popup.css");
  68. $this->add_linked_stylesheet("../css/c3.min.css");
  69. $this->add_linked_script('../js/jquery.layout.min.js');
  70. $this->add_linked_script('../js/jquery.ba-bbq.min.js');
  71. $this->add_linked_script("../js/jquery.treeview.js");
  72. $this->add_linked_script("../js/jquery.autocomplete.js");
  73. $this->add_linked_script("../js/date.js");
  74. $this->add_linked_script("../js/jquery-ui-timepicker-addon.js");
  75. $this->add_linked_script("../js/jquery-ui-timepicker-addon-i18n.min.js");
  76. $this->add_linked_script("../js/jquery.blockUI.js");
  77. $this->add_linked_script("../js/utils.js");
  78. $this->add_linked_script("../js/swfobject.js");
  79. $this->add_linked_script("../js/ckeditor/ckeditor.js");
  80. $this->add_linked_script("../js/ckeditor/adapters/jquery.js");
  81. $this->add_linked_script("../js/jquery.qtip-1.0.min.js");
  82. $this->add_linked_script('../js/property_field.js');
  83. $this->add_linked_script('../js/fg.menu.js');
  84. $this->add_linked_script('../js/icon_select.js');
  85. $this->add_linked_script('../js/raphael-min.js');
  86. $this->add_linked_script('../js/d3.js');
  87. $this->add_linked_script('../js/c3.js');
  88. $this->add_linked_script('../js/jquery.multiselect.js');
  89. $this->add_linked_script('../js/ajaxfileupload.js');
  90. $this->add_linked_script('../js/jquery.mousewheel.js');
  91. $this->add_linked_script('../js/jquery.magnific-popup.min.js');
  92. $this->add_linked_script('../js/breadcrumb.js');
  93. $this->add_linked_script('../js/moment.min.js');
  94. $sSearchAny = addslashes(Dict::S('UI:SearchValue:Any'));
  95. $sSearchNbSelected = addslashes(Dict::S('UI:SearchValue:NbSelected'));
  96. $this->add_dict_entry('UI:FillAllMandatoryFields');
  97. $this->add_dict_entry('UI:Button:Cancel');
  98. $this->add_dict_entry('UI:Button:Done');
  99. if (!$this->IsPrintableVersion())
  100. {
  101. $this->PrepareLayout();
  102. $this->add_script(
  103. <<<EOF
  104. function ShowAboutBox()
  105. {
  106. $.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php', {operation: 'about_box'}, function(data){
  107. $('body').append(data);
  108. });
  109. return false;
  110. }
  111. EOF
  112. );
  113. }
  114. }
  115. protected function IsMenuPaneVisible()
  116. {
  117. $bLeftPaneOpen = true;
  118. if (MetaModel::GetConfig()->Get('demo_mode'))
  119. {
  120. // Leave the pane opened
  121. }
  122. else
  123. {
  124. if (utils::ReadParam('force_menu_pane', null) === 0)
  125. {
  126. $bLeftPaneOpen = false;
  127. }
  128. elseif (appUserPreferences::GetPref('menu_pane', 'open') == 'closed')
  129. {
  130. $bLeftPaneOpen = false;
  131. }
  132. }
  133. return $bLeftPaneOpen;
  134. }
  135. protected function PrepareLayout()
  136. {
  137. if (MetaModel::GetConfig()->Get('demo_mode'))
  138. {
  139. // No pin button
  140. $sConfigureWestPane = '';
  141. }
  142. else
  143. {
  144. $sConfigureWestPane =
  145. <<<EOF
  146. myLayout.addPinBtn( "#tPinMenu", "west" );
  147. EOF;
  148. }
  149. $sInitClosed = $this->IsMenuPaneVisible() ? '' : 'initClosed: true,';
  150. $sJSDisconnectedMessage = json_encode(Dict::S('UI:DisconnectedDlgMessage'));
  151. $sJSTitle = json_encode(Dict::S('UI:DisconnectedDlgTitle'));
  152. $sJSLoginAgain = json_encode(Dict::S('UI:LoginAgain'));
  153. $sJSStayOnThePage = json_encode(Dict::S('UI:StayOnThePage'));
  154. $sJSDaysMin = json_encode(array(Dict::S('DayOfWeek-Sunday-Min'), Dict::S('DayOfWeek-Monday-Min'), Dict::S('DayOfWeek-Tuesday-Min'), Dict::S('DayOfWeek-Wednesday-Min'),
  155. Dict::S('DayOfWeek-Thursday-Min'), Dict::S('DayOfWeek-Friday-Min'), Dict::S('DayOfWeek-Saturday-Min')));
  156. $sJSMonthsShort = json_encode(array(Dict::S('Month-01-Short'), Dict::S('Month-02-Short'), Dict::S('Month-03-Short'), Dict::S('Month-04-Short'), Dict::S('Month-05-Short'), Dict::S('Month-06-Short'),
  157. Dict::S('Month-07-Short'), Dict::S('Month-08-Short'), Dict::S('Month-09-Short'), Dict::S('Month-10-Short'), Dict::S('Month-11-Short'), Dict::S('Month-12-Short')));
  158. $iFirstDayOfWeek = (int) Dict::S('Calendar-FirstDayOfWeek');
  159. $sJSDateFormat = json_encode(AttributeDate::GetFormat()->ToDatePicker());
  160. $sTimeFormat = AttributeDateTime::GetFormat()->ToTimeFormat();
  161. $oTimeFormat = new DateTimeFormat($sTimeFormat);
  162. $sJSTimeFormat = json_encode($oTimeFormat->ToDatePicker());
  163. $sJSLangShort = json_encode(strtolower(substr(Dict::GetUserLanguage(), 0, 2)));
  164. $sJSOk = json_encode(Dict::S('UI:Button:Ok'));
  165. $this->m_sInitScript =
  166. <<< EOF
  167. try
  168. {
  169. var myLayout; // a var is required because this page utilizes: myLayout.allowOverflow() method
  170. // Layout
  171. paneSize = GetUserPreference('menu_size', 300)
  172. myLayout = $('body').layout({
  173. west : {
  174. $sInitClosed minSize: 200, size: paneSize, spacing_open: 16, spacing_close: 16, slideTrigger_open: "click", hideTogglerOnSlide: true, enableCursorHotkey: false,
  175. onclose_end: function(name, elt, state, options, layout)
  176. {
  177. if (state.isSliding == false)
  178. {
  179. $('.menu-pane-exclusive').show();
  180. SetUserPreference('menu_pane', 'closed', true);
  181. }
  182. },
  183. onresize_end: function(name, elt, state, options, layout)
  184. {
  185. if (state.isSliding == false)
  186. {
  187. SetUserPreference('menu_size', state.size, true);
  188. }
  189. },
  190. onopen_end: function(name, elt, state, options, layout)
  191. {
  192. if (state.isSliding == false)
  193. {
  194. $('.menu-pane-exclusive').hide();
  195. SetUserPreference('menu_pane', 'open', true);
  196. }
  197. }
  198. },
  199. center: {
  200. onresize_end: function(name, elt, state, options, layout)
  201. {
  202. $('.v-resizable').each( function() {
  203. var fixedWidth = $(this).parent().innerWidth() - 6;
  204. $(this).width(fixedWidth);
  205. // Make sure it cannot be resized horizontally
  206. $(this).resizable('options', { minWidth: fixedWidth, maxWidth: fixedWidth });
  207. // Now adjust all the child 'items'
  208. var innerWidth = $(this).innerWidth() - 10;
  209. $(this).find('.item').width(innerWidth);
  210. });
  211. $('.panel-resized').trigger('resized');
  212. }
  213. }
  214. });
  215. window.clearTimeout(iPaneVisWatchDog);
  216. //myLayout.open( "west" );
  217. $('.ui-layout-resizer-west .ui-layout-toggler').css({background: 'transparent'});
  218. $sConfigureWestPane
  219. $('#left-pane').layout({ resizable: false, spacing_open: 0, south: { size: 94 }, enableCursorHotkey: false });
  220. // Tabs, using JQuery BBQ to store the history
  221. // The "tab widgets" to handle.
  222. var tabs = $('div[id^=tabbedContent]');
  223. // This selector will be reused when selecting actual tab widget A elements.
  224. var tab_a_selector = 'ul.ui-tabs-nav a';
  225. // Ugly patch for a change in the behavior of jQuery UI:
  226. // Before jQuery UI 1.9, tabs were always considered as "local" (opposed to Ajax)
  227. // when their href was beginning by #. Starting with 1.9, a <base> tag in the page
  228. // is taken into account and causes "local" tabs to be considered as Ajax
  229. // unless their URL is equal to the URL of the page...
  230. $('div[id^=tabbedContent] > ul > li > a').each(function() {
  231. var sHash = location.hash;
  232. var sHref = $(this).attr("href");
  233. if (sHref.match(/^#/))
  234. {
  235. var sCleanLocation = location.href.toString().replace(sHash, '').replace(/#$/, '');
  236. $(this).attr("href", sCleanLocation+$(this).attr("href"));
  237. }
  238. });
  239. // Enable tabs on all tab widgets. The `event` property must be overridden so
  240. // that the tabs aren't changed on click, and any custom event name can be
  241. // specified. Note that if you define a callback for the 'select' event, it
  242. // will be executed for the selected tab whenever the hash changes.
  243. tabs.tabs({
  244. event: 'change', 'show': function(event, ui) {
  245. $('.resizable', ui.panel).resizable(); // Make resizable everything that claims to be resizable !
  246. },
  247. beforeLoad: function( event, ui ) {
  248. if ( ui.tab.data('loaded') && (ui.tab.attr('data-cache') == 'true')) {
  249. event.preventDefault();
  250. return;
  251. }
  252. ui.panel.html('<div><img src="../images/indicator.gif"></div>');
  253. ui.jqXHR.success(function() {
  254. ui.tab.data( "loaded", true );
  255. });
  256. }
  257. });
  258. $('.resizable').filter(':visible').resizable();
  259. }
  260. catch(err)
  261. {
  262. // Do something with the error !
  263. alert(err);
  264. }
  265. EOF
  266. ;
  267. $this->add_ready_script(
  268. <<< EOF
  269. // Adjust initial size
  270. $('.v-resizable').each( function()
  271. {
  272. var parent_id = $(this).parent().id;
  273. // Restore the saved height
  274. var iHeight = GetUserPreference(parent_id+'_'+this.id+'_height', undefined);
  275. if (iHeight != undefined)
  276. {
  277. $(this).height(parseInt(iHeight, 10)); // Parse in base 10 !);
  278. }
  279. // Adjust the child 'item''s height and width to fit
  280. var container = $(this);
  281. var fixedWidth = container.parent().innerWidth() - 6;
  282. // Set the width to fit the parent
  283. $(this).width(fixedWidth);
  284. var headerHeight = $(this).find('.drag_handle').height();
  285. // Now adjust the width and height of the child 'item'
  286. container.find('.item').height(container.innerHeight() - headerHeight - 12).width(fixedWidth - 10);
  287. }
  288. );
  289. // Make resizable, vertically only everything that claims to be v-resizable !
  290. $('.v-resizable').resizable( { handles: 's', minHeight: $(this).find('.drag_handle').height(), minWidth: $(this).parent().innerWidth() - 6, maxWidth: $(this).parent().innerWidth() - 6, stop: function()
  291. {
  292. // Adjust the content
  293. var container = $(this);
  294. var headerHeight = $(this).find('.drag_handle').height();
  295. container.find('.item').height(container.innerHeight() - headerHeight - 12);//.width(container.innerWidth());
  296. var parent_id = $(this).parent().id;
  297. SetUserPreference(parent_id+'_'+this.id+'_height', $(this).height(), true); // true => persistent
  298. }
  299. } );
  300. // Tabs, using JQuery BBQ to store the history
  301. // The "tab widgets" to handle.
  302. var tabs = $('div[id^=tabbedContent]');
  303. // This selector will be reused when selecting actual tab widget A elements.
  304. var tab_a_selector = 'ul.ui-tabs-nav a';
  305. // Define our own click handler for the tabs, overriding the default.
  306. tabs.find( tab_a_selector ).click(function()
  307. {
  308. var state = {};
  309. // Get the id of this tab widget.
  310. var id = $(this).closest( 'div[id^=tabbedContent]' ).attr( 'id' );
  311. // Get the index of this tab.
  312. var idx = $(this).parent().prevAll().length;
  313. // Set the state!
  314. state[ id ] = idx;
  315. $.bbq.pushState( state );
  316. });
  317. // refresh the hash when the tab is changed (from a JS script)
  318. $('body').on( 'tabsactivate', '.ui-tabs', function(event, ui) {
  319. var state = {};
  320. // Get the id of this tab widget.
  321. var id = $(ui.newTab).closest( 'div[id^=tabbedContent]' ).attr( 'id' );
  322. // Get the index of this tab.
  323. var idx = $(ui.newTab).prevAll().length;
  324. // Set the state!
  325. state[ id ] = idx;
  326. $.bbq.pushState( state );
  327. });
  328. // Bind an event to window.onhashchange that, when the history state changes,
  329. // iterates over all tab widgets, changing the current tab as necessary.
  330. $(window).bind( 'hashchange', function(e)
  331. {
  332. // Iterate over all tab widgets.
  333. tabs.each(function()
  334. {
  335. // Get the index for this tab widget from the hash, based on the
  336. // appropriate id property. In jQuery 1.4, you should use e.getState()
  337. // instead of $.bbq.getState(). The second, 'true' argument coerces the
  338. // string value to a number.
  339. var idx = $.bbq.getState( this.id, true ) || 0;
  340. // Select the appropriate tab for this tab widget by triggering the custom
  341. // event specified in the .tabs() init above (you could keep track of what
  342. // tab each widget is on using .data, and only select a tab if it has
  343. // changed).
  344. $(this).find( tab_a_selector ).eq( idx ).triggerHandler( 'change' );
  345. });
  346. // Iterate over all truncated lists to find whether they are expanded or not
  347. $('a.truncated').each(function()
  348. {
  349. var state = $.bbq.getState( this.id, true ) || 'close';
  350. if (state == 'open')
  351. {
  352. $(this).trigger('open');
  353. }
  354. else
  355. {
  356. $(this).trigger('close');
  357. }
  358. });
  359. });
  360. // Shortcut menu actions
  361. $('.actions_button a').click( function() {
  362. aMatches = /#(.*)$/.exec(window.location.href);
  363. if (aMatches != null)
  364. {
  365. currentHash = aMatches[1];
  366. if ( /#(.*)$/.test(this.href))
  367. {
  368. this.href = this.href.replace(/#(.*)$/, '#'+currentHash);
  369. }
  370. }
  371. });
  372. // End of Tabs handling
  373. $(".date-pick").datepicker({
  374. showOn: 'button',
  375. buttonImage: '../images/calendar.png',
  376. buttonImageOnly: true,
  377. dateFormat: $sJSDateFormat,
  378. constrainInput: false,
  379. changeMonth: true,
  380. changeYear: true,
  381. dayNamesMin: $sJSDaysMin,
  382. monthNamesShort: $sJSMonthsShort,
  383. firstDay: $iFirstDayOfWeek
  384. });
  385. $(".datetime-pick").datetimepicker({
  386. showOn: 'button',
  387. buttonImage: '../images/calendar.png',
  388. buttonImageOnly: true,
  389. dateFormat: $sJSDateFormat,
  390. constrainInput: false,
  391. changeMonth: true,
  392. changeYear: true,
  393. dayNamesMin: $sJSDaysMin,
  394. monthNamesShort: $sJSMonthsShort,
  395. firstDay: $iFirstDayOfWeek,
  396. // time picker options
  397. timeFormat: $sJSTimeFormat,
  398. controlType: 'select',
  399. closeText: $sJSOk
  400. });
  401. if ($sJSLangShort != 'en')
  402. {
  403. $(".datetime-pick").datetimepicker('option', {
  404. timeText: $.timepicker.regional[$sJSLangShort].timeText,
  405. hourText: $.timepicker.regional[$sJSLangShort].hourText,
  406. minuteText: $.timepicker.regional[$sJSLangShort].minuteText,
  407. secondText: $.timepicker.regional[$sJSLangShort].secondText,
  408. currentText: $.timepicker.regional[$sJSLangShort].currentText,
  409. });
  410. }
  411. // Make sortable, everything that claims to be sortable
  412. $('.sortable').sortable( {axis: 'y', cursor: 'move', handle: '.drag_handle', stop: function()
  413. {
  414. if ($(this).hasClass('persistent'))
  415. {
  416. // remember the sort order for next time the page is loaded...
  417. sSerialized = $(this).sortable('serialize', {key: 'menu'});
  418. var sTemp = sSerialized.replace(/menu=/g, '');
  419. SetUserPreference(this.id+'_order', sTemp.replace(/&/g, ','), true); // true => persistent !
  420. }
  421. }
  422. });
  423. docWidth = $(document).width();
  424. $('#ModalDlg').dialog({ autoOpen: false, modal: true, width: 0.8*docWidth }); // JQuery UI dialogs
  425. ShowDebug();
  426. $('#logOffBtn>ul').popupmenu();
  427. $('.caselog_header').click( function () { $(this).toggleClass('open').next('.caselog_entry,.caselog_entry_html').toggle(); });
  428. $(document).ajaxSend(function(event, jqxhr, options) {
  429. jqxhr.setRequestHeader('X-Combodo-Ajax', 'true');
  430. });
  431. $(document).ajaxError(function(event, jqxhr, options) {
  432. if (jqxhr.status == 401)
  433. {
  434. $('<div>'+$sJSDisconnectedMessage+'</div>').dialog({
  435. modal:true,
  436. title: $sJSTitle,
  437. close: function() { $(this).remove(); },
  438. minWidth: 400,
  439. buttons: [
  440. { text: $sJSLoginAgain, click: function() { window.location.href= GetAbsoluteUrlAppRoot()+'pages/UI.php' } },
  441. { text: $sJSStayOnThePage, click: function() { $(this).dialog('close'); } }
  442. ]
  443. });
  444. }
  445. });
  446. EOF
  447. );
  448. $this->add_ready_script(InlineImage::FixImagesWidth());
  449. /*
  450. * Not used since the sorting of the tables is always performed server-side
  451. AttributeDateTime::InitTableSorter($this, 'custom_date_time');
  452. AttributeDate::InitTableSorter($this, 'custom_date');
  453. */
  454. $sUserPrefs = appUserPreferences::GetAsJSON();
  455. $this->add_script(
  456. <<<EOF
  457. // // for JQuery history
  458. // function history_callback(hash)
  459. // {
  460. // // do stuff that loads page content based on hash variable
  461. // var aMatches = /^tab_(.*)$/.exec(hash);
  462. // if (aMatches != null)
  463. // {
  464. // var tab = $('#'+hash);
  465. // tab.parents('div[id^=tabbedContent]:first').tabs('select', aMatches[1]);
  466. // }
  467. // }
  468. function goBack()
  469. {
  470. window.history.back();
  471. }
  472. function BackToDetails(sClass, id, sDefaultUrl, sOwnershipToken)
  473. {
  474. window.bInCancel = true;
  475. if (id > 0)
  476. {
  477. sToken = '';
  478. if (sOwnershipToken != undefined)
  479. {
  480. sToken = '&token='+sOwnershipToken;
  481. }
  482. window.location.href = AddAppContext(GetAbsoluteUrlAppRoot()+'pages/UI.php?operation=release_lock_and_details&class='+sClass+'&id='+id+sToken);
  483. }
  484. else
  485. {
  486. window.location.href = sDefaultUrl; // Already contains the context...
  487. }
  488. }
  489. function BackToList(sClass)
  490. {
  491. window.location.href = AddAppContext(GetAbsoluteUrlAppRoot()+'pages/UI.php?operation=search_oql&oql_class='+sClass+'&oql_clause=WHERE id=0');
  492. }
  493. function ShowDebug()
  494. {
  495. if ($('#rawOutput > div').html() != '')
  496. {
  497. $('#rawOutput').dialog( {autoOpen: true, modal:false, width: '80%'});
  498. }
  499. }
  500. var oUserPreferences = $sUserPrefs;
  501. // For disabling the CKEditor at init time when the corresponding textarea is disabled !
  502. CKEDITOR.plugins.add( 'disabler',
  503. {
  504. init : function( editor )
  505. {
  506. editor.on( 'instanceReady', function(e)
  507. {
  508. e.removeListener();
  509. $('#'+ editor.name).trigger('update');
  510. });
  511. }
  512. });
  513. function FixPaneVis()
  514. {
  515. $('.ui-layout-center, .ui-layout-north, .ui-layout-south').css({display: 'block'});
  516. }
  517. EOF
  518. );
  519. }
  520. /**
  521. * @param string $sId Identifies the item, to search after it in the current breadcrumb
  522. * @param string $sLabel Label of the breadcrumb item
  523. * @param string $sDescription More information, displayed as a tooltip
  524. * @param string $sUrl Specify a URL if the current URL as perceived on the browser side is not relevant
  525. * @param string $sIcon Icon (relative or absolute) path that will be displayed next to the label
  526. */
  527. public function SetBreadCrumbEntry($sId, $sLabel, $sDescription, $sUrl = '', $sIcon = '')
  528. {
  529. $this->bBreadCrumbEnabled = true;
  530. $this->sBreadCrumbEntryId = $sId;
  531. $this->sBreadCrumbEntryLabel = $sLabel;
  532. $this->sBreadCrumbEntryDescription = $sDescription;
  533. $this->sBreadCrumbEntryUrl = $sUrl;
  534. $this->sBreadCrumbEntryIcon = $sIcon;
  535. }
  536. /**
  537. * State that there will be no breadcrumb item for the current page
  538. */
  539. public function DisableBreadCrumb()
  540. {
  541. $this->bBreadCrumbEnabled = false;
  542. $this->sBreadCrumbEntryId = null;
  543. $this->sBreadCrumbEntryLabel = null;
  544. $this->sBreadCrumbEntryDescription = null;
  545. $this->sBreadCrumbEntryUrl = null;
  546. $this->sBreadCrumbEntryIcon = null;
  547. }
  548. public function AddToMenu($sHtml)
  549. {
  550. $this->m_sMenu .= $sHtml;
  551. }
  552. public function GetSiloSelectionForm()
  553. {
  554. // List of visible Organizations
  555. $iCount = 0;
  556. $oSet = null;
  557. if (MetaModel::IsValidClass('Organization'))
  558. {
  559. // Display the list of *favorite* organizations... but keeping in mind what is the real number of organizations
  560. $aFavoriteOrgs = appUserPreferences::GetPref('favorite_orgs', null);
  561. $oSearchFilter = new DBObjectSearch('Organization');
  562. $oSearchFilter->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', true);
  563. $oSet = new CMDBObjectSet($oSearchFilter);
  564. $iCount = $oSet->Count(); // total number of existing Orgs
  565. // Now get the list of Orgs to be displayed in the menu
  566. $oSearchFilter = DBObjectSearch::FromOQL(ApplicationMenu::GetFavoriteSiloQuery());
  567. $oSearchFilter->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', true);
  568. if (!empty($aFavoriteOrgs))
  569. {
  570. $oSearchFilter->AddCondition('id', $aFavoriteOrgs, 'IN');
  571. }
  572. $oSet = new CMDBObjectSet($oSearchFilter); // List of favorite orgs
  573. }
  574. switch($iCount)
  575. {
  576. case 0:
  577. // No such dimension/silo => nothing to select
  578. $sHtml = '<div id="SiloSelection"><!-- nothing to select --></div>';
  579. break;
  580. case 1:
  581. // Only one possible choice... no selection, but display the value
  582. $oOrg = $oSet->Fetch();
  583. $sHtml = '<div id="SiloSelection">'.$oOrg->GetName().'</div>';
  584. $sHtml .= '';
  585. break;
  586. default:
  587. $sHtml = '';
  588. $oAppContext = new ApplicationContext();
  589. $iCurrentOrganization = $oAppContext->GetCurrentValue('org_id');
  590. $sHtml = '<div id="SiloSelection">';
  591. $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();">';
  592. $sFavoriteOrgs = '';
  593. $oWidget = new UIExtKeyWidget('Organization', 'org_id', '', true /* search mode */);
  594. $sHtml .= $oWidget->Display($this, 50, false, '', $oSet, $iCurrentOrganization, 'org_id', false, 'c[org_id]', '',
  595. array('iFieldSize' => 20, 'iMinChars' => MetaModel::GetConfig()->Get('min_autocomplete_chars'), 'sDefaultValue' => Dict::S('UI:AllOrganizations')),
  596. null, 'select', false /* bSearchMultiple */);
  597. $this->add_ready_script('$("#org_id").bind("extkeychange", function() { $("#SiloSelection form").submit(); } )');
  598. $this->add_ready_script("$('#label_org_id').click( function() { if ($('#org_id').val() == '') { $(this).val(''); } } );\n");
  599. // Add other dimensions/context information to this form
  600. $oAppContext->Reset('org_id'); // org_id is handled above and we want to be able to change it here !
  601. $oAppContext->Reset('menu'); // don't pass the menu, since a menu may expect more parameters
  602. $sHtml .= $oAppContext->GetForForm(); // Pass what remains, if anything...
  603. $sHtml .= '</form>';
  604. $sHtml .= '</div>';
  605. }
  606. return $sHtml;
  607. }
  608. public function DisplayMenu()
  609. {
  610. // Display the menu
  611. $oAppContext = new ApplicationContext();
  612. $iAccordionIndex = 0;
  613. ApplicationMenu::DisplayMenu($this, $oAppContext->GetAsHash());
  614. }
  615. /**
  616. * Outputs (via some echo) the complete HTML page by assembling all its elements
  617. */
  618. public function output()
  619. {
  620. $sAbsURLAppRoot = addslashes($this->m_sRootUrl);
  621. //$this->set_base($this->m_sRootUrl.'pages/');
  622. $sForm = $this->GetSiloSelectionForm();
  623. $this->DisplayMenu(); // Compute the menu
  624. // Call the extensions to add content to the page, so that they can also add styles or scripts
  625. $sBannerExtraHtml = '';
  626. foreach (MetaModel::EnumPlugins('iPageUIExtension') as $oExtensionInstance)
  627. {
  628. $sBannerExtraHtml .= $oExtensionInstance->GetBannerHtml($this);
  629. }
  630. $sNorthPane = '';
  631. foreach (MetaModel::EnumPlugins('iPageUIExtension') as $oExtensionInstance)
  632. {
  633. $sNorthPane .= $oExtensionInstance->GetNorthPaneHtml($this);
  634. }
  635. if (UserRights::IsAdministrator() && ExecutionKPI::IsEnabled())
  636. {
  637. $sNorthPane .= '<div id="admin-banner"><span style="padding:5px;">'.ExecutionKPI::GetDescription().'<span></div>';
  638. }
  639. //$sSouthPane = '<p>Peak memory Usage: '.sprintf('%.3f MB', memory_get_peak_usage(true) / (1024*1024)).'</p>';
  640. $sSouthPane = '';
  641. foreach (MetaModel::EnumPlugins('iPageUIExtension') as $oExtensionInstance)
  642. {
  643. $sSouthPane .= $oExtensionInstance->GetSouthPaneHtml($this);
  644. }
  645. // Render the tabs in the page (if any)
  646. $this->s_content = $this->m_oTabs->RenderIntoContent($this->s_content, $this);
  647. // Put here the 'ready scripts' that must be executed after all others
  648. $aMultiselectOptions = array(
  649. 'header' => true,
  650. 'checkAllText' => Dict::S('UI:SearchValue:CheckAll'),
  651. 'uncheckAllText' => Dict::S('UI:SearchValue:UncheckAll'),
  652. 'noneSelectedText' => Dict::S('UI:SearchValue:Any'),
  653. 'selectedText' => Dict::S('UI:SearchValue:NbSelected'),
  654. 'selectedList' => 1,
  655. );
  656. $sJSMultiselectOptions = json_encode($aMultiselectOptions);
  657. $this->add_ready_script(
  658. <<<EOF
  659. // Since the event is only triggered when the hash changes, we need to trigger
  660. // the event now, to handle the hash the page may have loaded with.
  661. $(window).trigger( 'hashchange' );
  662. // Some table are sort-able, some are not, let's fix this
  663. $('table.listResults').each( function() { FixTableSorter($(this)); } );
  664. $('.multiselect').multiselect($sJSMultiselectOptions);
  665. FixSearchFormsDisposition();
  666. EOF
  667. );
  668. $iBreadCrumbMaxCount = utils::GetConfig()->Get('breadcrumb.max_count');
  669. if ($iBreadCrumbMaxCount > 1)
  670. {
  671. $oConfig = MetaModel::GetConfig();
  672. $siTopInstanceId = json_encode(utils::GetAbsoluteUrlAppRoot().'==='.$oConfig->GetDBHost().'/'.$oConfig->GetDBName().'/'.$oConfig->GetDBSubname());
  673. if ($this->bBreadCrumbEnabled)
  674. {
  675. if (is_null($this->sBreadCrumbEntryId))
  676. {
  677. $this->sBreadCrumbEntryId = $this->s_title;
  678. $this->sBreadCrumbEntryLabel = $this->s_title;
  679. $this->sBreadCrumbEntryDescription = $this->s_title;
  680. $this->sBreadCrumbEntryUrl = '';
  681. $this->sBreadCrumbEntryIcon = utils::GetAbsoluteUrlAppRoot().'images/wrench.png';
  682. }
  683. $sNewEntry = json_encode(array('id' => $this->sBreadCrumbEntryId, 'url' => $this->sBreadCrumbEntryUrl, 'label' => htmlentities($this->sBreadCrumbEntryLabel, ENT_QUOTES, 'UTF-8'), 'description' => htmlentities($this->sBreadCrumbEntryDescription, ENT_QUOTES, 'UTF-8'), 'icon' => $this->sBreadCrumbEntryIcon));
  684. }
  685. else
  686. {
  687. $sNewEntry = 'null';
  688. }
  689. $this->add_ready_script(
  690. <<<EOF
  691. $('#itop-breadcrumb').breadcrumb({itop_instance_id: $siTopInstanceId, new_entry: $sNewEntry, max_count: $iBreadCrumbMaxCount});
  692. EOF
  693. );
  694. }
  695. if ($this->GetOutputFormat() == 'html')
  696. {
  697. foreach($this->a_headers as $s_header)
  698. {
  699. header($s_header);
  700. }
  701. }
  702. $s_captured_output = $this->ob_get_clean_safe();
  703. $sHtml = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
  704. $sHtml .= "<html>\n";
  705. $sHtml .= "<head>\n";
  706. // Make sure that Internet Explorer renders the page using its latest/highest/greatest standards !
  707. $sHtml .= "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n";
  708. $sHtml .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
  709. $sHtml .= "<title>".htmlentities($this->s_title, ENT_QUOTES, 'UTF-8')."</title>\n";
  710. $sHtml .= $this->get_base_tag();
  711. // Stylesheets MUST be loaded before any scripts otherwise
  712. // jQuery scripts may face some spurious problems (like failing on a 'reload')
  713. foreach($this->a_linked_stylesheets as $a_stylesheet)
  714. {
  715. if (strpos($a_stylesheet['link'], '?') === false)
  716. {
  717. $s_stylesheet = $a_stylesheet['link']."?itopversion=".ITOP_VERSION;
  718. }
  719. else
  720. {
  721. $s_stylesheet = $a_stylesheet['link']."&itopversion=".ITOP_VERSION;
  722. }
  723. if ($a_stylesheet['condition'] != "")
  724. {
  725. $sHtml .= "<!--[if {$a_stylesheet['condition']}]>\n";
  726. }
  727. $sHtml .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$s_stylesheet}\" />\n";
  728. if ($a_stylesheet['condition'] != "")
  729. {
  730. $sHtml .= "<![endif]-->\n";
  731. }
  732. }
  733. // special stylesheet for printing, hides the navigation gadgets
  734. $sHtml .= "<link rel=\"stylesheet\" media=\"print\" type=\"text/css\" href=\"../css/print.css?itopversion=".ITOP_VERSION."\" />\n";
  735. if ($this->GetOutputFormat() == 'html')
  736. {
  737. $sHtml .= $this->output_dict_entries(true); // before any script so that they can benefit from the translations
  738. foreach($this->a_linked_scripts as $s_script)
  739. {
  740. // Make sure that the URL to the script contains the application's version number
  741. // so that the new script do NOT get reloaded from the cache when the application is upgraded
  742. if (strpos($s_script, '?') === false)
  743. {
  744. $s_script .= "?itopversion=".ITOP_VERSION;
  745. }
  746. else
  747. {
  748. $s_script .= "&itopversion=".ITOP_VERSION;
  749. }
  750. $sHtml .= "<script type=\"text/javascript\" src=\"$s_script\"></script>\n";
  751. }
  752. if (!$this->IsPrintableVersion())
  753. {
  754. $this->add_script("var iPaneVisWatchDog = window.setTimeout('FixPaneVis()',5000);");
  755. }
  756. $this->add_script("\$(document).ready(function() {\n{$this->m_sInitScript};\nwindow.setTimeout('onDelayedReady()',10)\n});");
  757. if ($this->IsPrintableVersion())
  758. {
  759. $this->add_ready_script(
  760. <<<EOF
  761. var sHiddeableChapters = '<div class="light ui-tabs ui-widget ui-widget-content ui-corner-all">';
  762. sHiddeableChapters += '<ul role="tablist" class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">';
  763. for (sId in oHiddeableChapters)
  764. {
  765. sHiddeableChapters += '<li tabindex="-1" role="tab" class="ui-state-default ui-corner-top hideable-chapter" chapter-id="'+sId+'"><span class="tab ui-tabs-anchor">' + oHiddeableChapters[sId] + '</span></li>';
  766. //alert(oHiddeableChapters[sId]);
  767. }
  768. sHiddeableChapters += '</ul></div>';
  769. $('#hiddeable_chapters').html(sHiddeableChapters);
  770. $('.hideable-chapter').click(function(){
  771. var sChapterId = $(this).attr('chapter-id');
  772. $('#'+sChapterId).toggle();
  773. $(this).toggleClass('strikethrough');
  774. });
  775. $('fieldset').each(function() {
  776. var jLegend = $(this).find('legend');
  777. jLegend.remove();
  778. $(this).wrapInner('<span></span>').prepend(jLegend);
  779. });
  780. $('legend').css('cursor', 'pointer').click(function(){
  781. $(this).parent('fieldset').toggleClass('not-printable strikethrough');
  782. });
  783. EOF
  784. );
  785. }
  786. if (count($this->m_aReadyScripts)>0)
  787. {
  788. $this->add_script("\nonDelayedReady = function() {\n".implode("\n", $this->m_aReadyScripts)."\n}\n");
  789. }
  790. if (count($this->a_scripts)>0)
  791. {
  792. $sHtml .= "<script type=\"text/javascript\">\n";
  793. foreach($this->a_scripts as $s_script)
  794. {
  795. $sHtml .= "$s_script\n";
  796. }
  797. $sHtml .= "</script>\n";
  798. }
  799. }
  800. if (count($this->a_styles)>0)
  801. {
  802. $sHtml .= "<style>\n";
  803. foreach($this->a_styles as $s_style)
  804. {
  805. $sHtml .= "$s_style\n";
  806. }
  807. $sHtml .= "</style>\n";
  808. }
  809. $sHtml .= "<link rel=\"search\" type=\"application/opensearchdescription+xml\" title=\"iTop\" href=\"".utils::GetAbsoluteUrlAppRoot()."pages/opensearch.xml.php\" />\n";
  810. $sHtml .= "<link rel=\"shortcut icon\" href=\"".utils::GetAbsoluteUrlAppRoot()."images/favicon.ico?itopversion=".ITOP_VERSION."\" />\n";
  811. $sHtml .= "</head>\n";
  812. $sBodyClass = "";
  813. if ($this->IsPrintableVersion())
  814. {
  815. $sBodyClass = 'printable-version';
  816. }
  817. $sHtml .= "<body class=\"$sBodyClass\">\n";
  818. if ($this->IsPrintableVersion())
  819. {
  820. $sHtml .= "<div class=\"explain-printable not-printable\">";
  821. $sHtml .= '<p>'.Dict::Format('UI:ExplainPrintable', '<img src="../images/eye-open-555.png" style="vertical-align:middle">').'</p>';
  822. $sHtml .= "<div id=\"hiddeable_chapters\"></div>";
  823. $sHtml .= '<button onclick="window.print()">'.htmlentities(Dict::S('UI:Button:GoPrint'), ENT_QUOTES, 'UTF-8').'</button>';
  824. $sHtml .= '&nbsp;';
  825. $sHtml .= '<button onclick="window.close()">'.htmlentities(Dict::S('UI:Button:Cancel'), ENT_QUOTES, 'UTF-8').'</button>';
  826. $sHtml .= "</div>";
  827. }
  828. // Render the revision number
  829. if (ITOP_REVISION == '$WCREV$')
  830. {
  831. // This is NOT a version built using the buil system, just display the main version
  832. $sVersionString = Dict::Format('UI:iTopVersion:Short', ITOP_VERSION);
  833. }
  834. else
  835. {
  836. // This is a build made from SVN, let display the full information
  837. $sVersionString = Dict::Format('UI:iTopVersion:Long', ITOP_VERSION, ITOP_REVISION, ITOP_BUILD_DATE);
  838. }
  839. // Render the text of the global search form
  840. $sText = htmlentities(utils::ReadParam('text', '', false, 'raw_data'), ENT_QUOTES, 'UTF-8');
  841. $sOnClick = " onclick=\"if ($('#global-search-input').val() != '') { $('#global-search form').submit(); } \"";
  842. if (empty($sText))
  843. {
  844. $sText = Dict::S("UI:YourSearch");
  845. }
  846. if ($this->IsPrintableVersion())
  847. {
  848. $sHtml .= ' <!-- Beginning of page content -->';
  849. $sHtml .= self::FilterXSS($this->s_content);
  850. $sHtml .= ' <!-- End of page content -->';
  851. }
  852. elseif ($this->GetOutputFormat() == 'html')
  853. {
  854. $oAppContext = new ApplicationContext();
  855. $sUserName = UserRights::GetUser();
  856. $sIsAdmin = UserRights::IsAdministrator() ? '(Administrator)' : '';
  857. if (UserRights::IsAdministrator())
  858. {
  859. $sLogonMessage = Dict::Format('UI:LoggedAsMessage+Admin', $sUserName);
  860. }
  861. else
  862. {
  863. $sLogonMessage = Dict::Format('UI:LoggedAsMessage', $sUserName);
  864. }
  865. $sLogOffMenu = "<span id=\"logOffBtn\"><ul><li><img src=\"../images/on-off-menu.png\"><ul>";
  866. $sLogOffMenu .= "<li><span>$sLogonMessage</span></li>\n";
  867. $aActions = array();
  868. $oPrefs = new URLPopupMenuItem('UI:Preferences', Dict::S('UI:Preferences'), utils::GetAbsoluteUrlAppRoot()."pages/preferences.php?".$oAppContext->GetForLink());
  869. $aActions[$oPrefs->GetUID()] = $oPrefs->GetMenuItem();
  870. if (utils::CanLogOff())
  871. {
  872. $oLogOff = new URLPopupMenuItem('UI:LogOffMenu', Dict::S('UI:LogOffMenu'), utils::GetAbsoluteUrlAppRoot().'pages/logoff.php?operation=do_logoff');
  873. $aActions[$oLogOff->GetUID()] = $oLogOff->GetMenuItem();
  874. }
  875. if (UserRights::CanChangePassword())
  876. {
  877. $oChangePwd = new URLPopupMenuItem('UI:ChangePwdMenu', Dict::S('UI:ChangePwdMenu'), utils::GetAbsoluteUrlAppRoot().'pages/UI.php?loginop=change_pwd');
  878. $aActions[$oChangePwd->GetUID()] = $oChangePwd->GetMenuItem();
  879. }
  880. utils::GetPopupMenuItems($this, iPopupMenuExtension::MENU_USER_ACTIONS, null, $aActions);
  881. $oAbout = new JSPopupMenuItem('UI:AboutBox', Dict::S('UI:AboutBox'), 'return ShowAboutBox();');
  882. $aActions[$oAbout->GetUID()] = $oAbout->GetMenuItem();
  883. $sLogOffMenu .= $this->RenderPopupMenuItems($aActions);
  884. $sRestrictions = '';
  885. if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE))
  886. {
  887. if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE))
  888. {
  889. $sRestrictions = Dict::S('UI:AccessRO-All');
  890. }
  891. }
  892. elseif (!MetaModel::DBHasAccess(ACCESS_USER_WRITE))
  893. {
  894. $sRestrictions = Dict::S('UI:AccessRO-Users');
  895. }
  896. $sApplicationBanner = '';
  897. if (strlen($sRestrictions) > 0)
  898. {
  899. $sAdminMessage = trim(MetaModel::GetConfig()->Get('access_message'));
  900. $sApplicationBanner .= '<div id="admin-banner">';
  901. $sApplicationBanner .= '<img src="../images/locked.png" style="vertical-align:middle;">';
  902. $sApplicationBanner .= '&nbsp;<b>'.$sRestrictions.'</b>';
  903. if (strlen($sAdminMessage) > 0)
  904. {
  905. $sApplicationBanner .= '&nbsp;<b>'.$sAdminMessage.'</b>';
  906. }
  907. $sApplicationBanner .= '</div>';
  908. }
  909. if(strlen($this->m_sMessage))
  910. {
  911. $sApplicationBanner .= '<div id="admin-banner"><span style="padding:5px;">'.$this->m_sMessage.'<span></div>';
  912. }
  913. $sApplicationBanner .= $sBannerExtraHtml;
  914. if (!empty($sNorthPane))
  915. {
  916. $sNorthPane = '<div id="top-pane" class="ui-layout-north">'.$sNorthPane.'</div>';
  917. }
  918. if (!empty($sSouthPane))
  919. {
  920. $sSouthPane = '<div id="bottom-pane" class="ui-layout-south">'.$sSouthPane.'</div>';
  921. }
  922. $sIconUrl = Utils::GetConfig()->Get('app_icon_url');
  923. $sOnlineHelpUrl = MetaModel::GetConfig()->Get('online_help');
  924. //$sLogOffMenu = "<span id=\"logOffBtn\" style=\"height:55px;padding:0;margin:0;\"><img src=\"../images/onOffBtn.png\"></span>";
  925. $sDisplayIcon = utils::GetAbsoluteUrlAppRoot().'images/itop-logo.png?itopversion='.ITOP_VERSION;
  926. if (file_exists(MODULESROOT.'branding/main-logo.png'))
  927. {
  928. $sDisplayIcon = utils::GetAbsoluteUrlModulesRoot().'branding/main-logo.png?itopversion='.ITOP_VERSION;
  929. }
  930. $sHtml .= $sNorthPane;
  931. $sHtml .= '<div id="left-pane" class="ui-layout-west">';
  932. $sHtml .= '<!-- Beginning of the left pane -->';
  933. $sHtml .= ' <div class="ui-layout-north">';
  934. $sHtml .= ' <div id="header-logo">';
  935. $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>';
  936. $sHtml .= ' </div>';
  937. $sHtml .= ' <div class="header-menu">';
  938. if (!MetaModel::GetConfig()->Get('demo_mode'))
  939. {
  940. $sHtml .= ' <div class="icon ui-state-default ui-corner-all"><span id="tPinMenu" class="ui-icon ui-icon-pin-w">pin</span></div>';
  941. }
  942. $sHtml .= ' <div style="text-align:center;">'.self::FilterXSS($sForm).'</div>';
  943. $sHtml .= ' </div>';
  944. $sHtml .= ' </div>';
  945. $sHtml .= ' <div id="menu" class="ui-layout-center">';
  946. $sHtml .= ' <div id="inner_menu">';
  947. $sHtml .= ' <div id="accordion">';
  948. $sHtml .= self::FilterXSS($this->m_sMenu);
  949. $sHtml .= ' <!-- Beginning of the accordion menu -->';
  950. $sHtml .= ' <!-- End of the accordion menu-->';
  951. $sHtml .= ' </div>';
  952. $sHtml .= ' </div> <!-- /inner menu -->';
  953. $sHtml .= ' </div> <!-- /menu -->';
  954. $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?itopversion='.ITOP_VERSION.'"/></a></div></div>';
  955. $sHtml .= '<!-- End of the left pane -->';
  956. $sHtml .= '</div>';
  957. $sHtml .= '<div class="ui-layout-center">';
  958. $sHtml .= ' <div id="top-bar" class="ui-helper-clearfix" style="width:100%">';
  959. $sHtml .= self::FilterXSS($sApplicationBanner);
  960. $GoHomeInitialStyle = $this->IsMenuPaneVisible() ? 'display: none;' : '';
  961. $sHtml .= ' <table id="top-bar-table">';
  962. $sHtml .= ' <tr>';
  963. $sHtml .= ' <td id="open-left-pane" class="menu-pane-exclusive" style="'.$GoHomeInitialStyle.'" onclick="$(\'body\').layout().open(\'west\');">';
  964. $sHtml .= ' <img src="../images/menu.png">';
  965. $sHtml .= ' </td>';
  966. $sHtml .= ' <td id="go-home" class="menu-pane-exclusive" style="'.$GoHomeInitialStyle.'">';
  967. $sHtml .= ' <a href="'.utils::GetAbsoluteUrlAppRoot().'pages/UI.php"><img src="../images/home.png"></a>';
  968. $sHtml .= ' </td>';
  969. $sHtml .= ' <td class="top-bar-spacer menu-pane-exclusive" style="'.$GoHomeInitialStyle.'">';
  970. $sHtml .= ' </td>';
  971. $sHtml .= ' <td id="top-bar-table-breadcrumb">';
  972. $sHtml .= ' <div id="itop-breadcrumb"></div>';
  973. $sHtml .= ' </td>';
  974. $sHtml .= ' <td id="top-bar-table-search">';
  975. $sHtml .= ' <div id="global-search"><form action="'.utils::GetAbsoluteUrlAppRoot().'pages/UI.php"><table><tr><td></td><td><div id="global-search-area"><input id="global-search-input" type="text" name="text" placeholder="'.$sText.'"></input><div '.$sOnClick.' id="global-search-image"></div></div></td>';
  976. $sHtml .= ' <td><a id="help-link" href="'.$sOnlineHelpUrl.'" target="_blank"><img title="'.Dict::S('UI:Help').'" src="../images/help.png?itopversion='.ITOP_VERSION.'"/></td>';
  977. $sHtml .= ' <td>'.self::FilterXSS($sLogOffMenu).'</td><td><input type="hidden" name="operation" value="full_text"/></td></tr></table></form></div>';
  978. $sHtml .= ' </td>';
  979. $sHtml .= ' </tr>';
  980. $sHtml .= ' </table>';
  981. // $sHtml .= ' <div id="global-search"><form action="'.utils::GetAbsoluteUrlAppRoot().'pages/UI.php"><table><tr><td></td><td><div id="global-search-area"><input id="global-search-input" type="text" name="text" placeholder="'.$sText.'"></input><div '.$sOnClick.' id="global-search-image"></div></div></td>';
  982. // $sHtml .= '<td><a id="help-link" href="'.$sOnlineHelpUrl.'" target="_blank"><img title="'.Dict::S('UI:Help').'" src="../images/help.png?itopversion='.ITOP_VERSION.'"/></td>';
  983. // $sHtml .= '<td>'.self::FilterXSS($sLogOffMenu).'</td><td><input type="hidden" name="operation" value="full_text"/></td></tr></table></form></div>';
  984. // $sHtml .= ' <div id="itop-breadcrumb"></div>';
  985. $sHtml .= ' </div>';
  986. $sHtml .= ' <div class="ui-layout-content" style="overflow:auto;">';
  987. $sHtml .= ' <!-- Beginning of page content -->';
  988. $sHtml .= self::FilterXSS($this->s_content);
  989. $sHtml .= ' <!-- End of page content -->';
  990. $sHtml .= ' </div>';
  991. $sHtml .= '</div>';
  992. $sHtml .= $sSouthPane;
  993. // Add the captured output
  994. if (trim($s_captured_output) != "")
  995. {
  996. $sHtml .= "<div id=\"rawOutput\" title=\"Debug Output\"><div style=\"height:500px; overflow-y:auto;\">".self::FilterXSS($s_captured_output)."</div></div>\n";
  997. }
  998. $sHtml .= "<div id=\"at_the_end\">".self::FilterXSS($this->s_deferred_content)."</div>";
  999. $sHtml .= "<div style=\"display:none\" title=\"ex2\" id=\"ex2\">Please wait...</div>\n"; // jqModal Window
  1000. $sHtml .= "<div style=\"display:none\" title=\"dialog\" id=\"ModalDlg\"></div>";
  1001. $sHtml .= "<div style=\"display:none\" id=\"ajax_content\"></div>";
  1002. }
  1003. else
  1004. {
  1005. $sHtml .= self::FilterXSS($this->s_content);
  1006. }
  1007. $sHtml .= "</body>\n";
  1008. $sHtml .= "</html>\n";
  1009. if ($this->GetOutputFormat() == 'html')
  1010. {
  1011. $oKPI = new ExecutionKPI();
  1012. echo $sHtml;
  1013. $oKPI->ComputeAndReport('Echoing ('.round(strlen($sHtml) / 1024).' Kb)');
  1014. }
  1015. else if ($this->GetOutputFormat() == 'pdf' && $this->IsOutputFormatAvailable('pdf') )
  1016. {
  1017. if (@is_readable(APPROOT.'lib/MPDF/mpdf.php'))
  1018. {
  1019. require_once(APPROOT.'lib/MPDF/mpdf.php');
  1020. $oMPDF = new mPDF('c');
  1021. $oMPDF->mirroMargins = false;
  1022. if ($this->a_base['href'] != '')
  1023. {
  1024. $oMPDF->setBasePath($this->a_base['href']); // Seems that the <BASE> tag is not recognized by mPDF...
  1025. }
  1026. $oMPDF->showWatermarkText = true;
  1027. if ($this->GetOutputOption('pdf', 'template_path'))
  1028. {
  1029. $oMPDF->setImportUse(); // Allow templates
  1030. $oMPDF->SetDocTemplate ($this->GetOutputOption('pdf', 'template_path'), 1);
  1031. }
  1032. $oMPDF->WriteHTML($sHtml);
  1033. $sOutputName = $this->s_title.'.pdf';
  1034. if ($this->GetOutputOption('pdf', 'output_name'))
  1035. {
  1036. $sOutputName = $this->GetOutputOption('pdf', 'output_name');
  1037. }
  1038. $oMPDF->Output($sOutputName, 'I');
  1039. }
  1040. }
  1041. DBSearch::RecordQueryTrace();
  1042. ExecutionKPI::ReportStats();
  1043. }
  1044. public function AddTabContainer($sTabContainer, $sPrefix = '')
  1045. {
  1046. $this->add($this->m_oTabs->AddTabContainer($sTabContainer, $sPrefix));
  1047. }
  1048. public function AddToTab($sTabContainer, $sTabLabel, $sHtml)
  1049. {
  1050. $this->add($this->m_oTabs->AddToTab($sTabContainer, $sTabLabel, $sHtml));
  1051. }
  1052. public function SetCurrentTabContainer($sTabContainer = '')
  1053. {
  1054. return $this->m_oTabs->SetCurrentTabContainer($sTabContainer);
  1055. }
  1056. public function SetCurrentTab($sTabLabel = '')
  1057. {
  1058. return $this->m_oTabs->SetCurrentTab($sTabLabel);
  1059. }
  1060. /**
  1061. * Add a tab which content will be loaded asynchronously via the supplied URL
  1062. *
  1063. * Limitations:
  1064. * Cross site scripting is not not allowed for security reasons. Use a normal tab with an IFRAME if you want to pull content from another server.
  1065. * Static content cannot be added inside such tabs.
  1066. *
  1067. * @param string $sTabLabel The (localised) label of the tab
  1068. * @param string $sUrl The URL to load (on the same server)
  1069. * @param boolean $bCache Whether or not to cache the content of the tab once it has been loaded. flase will cause the tab to be reloaded upon each activation.
  1070. * @since 2.0.3
  1071. */
  1072. public function AddAjaxTab($sTabLabel, $sUrl, $bCache = true)
  1073. {
  1074. $this->add($this->m_oTabs->AddAjaxTab($sTabLabel, $sUrl, $bCache));
  1075. }
  1076. public function GetCurrentTab()
  1077. {
  1078. return $this->m_oTabs->GetCurrentTab();
  1079. }
  1080. public function RemoveTab($sTabLabel, $sTabContainer = null)
  1081. {
  1082. $this->m_oTabs->RemoveTab($sTabLabel, $sTabContainer);
  1083. }
  1084. /**
  1085. * Finds the tab whose title matches a given pattern
  1086. * @return mixed The name of the tab as a string or false if not found
  1087. */
  1088. public function FindTab($sPattern, $sTabContainer = null)
  1089. {
  1090. return $this->m_oTabs->FindTab($sPattern, $sTabContainer);
  1091. }
  1092. /**
  1093. * Make the given tab the active one, as if it were clicked
  1094. * DOES NOT WORK: apparently in the *old* version of jquery
  1095. * that we are using this is not supported... TO DO upgrade
  1096. * the whole jquery bundle...
  1097. */
  1098. public function SelectTab($sTabContainer, $sTabLabel)
  1099. {
  1100. $this->add_ready_script($this->m_oTabs->SelectTab($sTabContainer, $sTabLabel));
  1101. }
  1102. public function StartCollapsibleSection($sSectionLabel, $bOpen = false)
  1103. {
  1104. $this->add($this->GetStartCollapsibleSection($sSectionLabel, $bOpen));
  1105. }
  1106. public function GetStartCollapsibleSection($sSectionLabel, $bOpen = false)
  1107. {
  1108. $sHtml = '';
  1109. static $iSectionId = 0;
  1110. $sImgStyle = $bOpen ? ' open' : '';
  1111. $sHtml .= "<a id=\"LnkCollapse_$iSectionId\" class=\"CollapsibleLabel{$sImgStyle}\" href=\"#\">$sSectionLabel</a></br>\n";
  1112. $sStyle = $bOpen ? '' : 'style="display:none" ';
  1113. $sHtml .= "<div id=\"Collapse_$iSectionId\" $sStyle>";
  1114. $this->add_ready_script("\$(\"#LnkCollapse_$iSectionId\").click(function() {\$(\"#Collapse_$iSectionId\").slideToggle('normal'); $(\"#LnkCollapse_$iSectionId\").toggleClass('open');});");
  1115. //$this->add_ready_script("$('#LnkCollapse_$iSectionId').hide();");
  1116. $iSectionId++;
  1117. return $sHtml;
  1118. }
  1119. public function EndCollapsibleSection()
  1120. {
  1121. $this->add($this->GetEndCollapsibleSection());
  1122. }
  1123. public function GetEndCollapsibleSection()
  1124. {
  1125. return "</div>";
  1126. }
  1127. public function add($sHtml)
  1128. {
  1129. if (($this->m_oTabs->GetCurrentTabContainer() != '') && ($this->m_oTabs->GetCurrentTab() != ''))
  1130. {
  1131. $this->m_oTabs->AddToCurrentTab($sHtml);
  1132. }
  1133. else
  1134. {
  1135. parent::add($sHtml);
  1136. }
  1137. }
  1138. /**
  1139. * Records the current state of the 'html' part of the page output
  1140. * @return mixed The current state of the 'html' output
  1141. */
  1142. public function start_capture()
  1143. {
  1144. $sCurrentTabContainer = $this->m_oTabs->GetCurrentTabContainer();
  1145. $sCurrentTab = $this->m_oTabs->GetCurrentTab();
  1146. if (!empty($sCurrentTabContainer) && !empty($sCurrentTab))
  1147. {
  1148. $iOffset = $this->m_oTabs->GetCurrentTabLength();
  1149. return array('tc' => $sCurrentTabContainer, 'tab' => $sCurrentTab, 'offset' => $iOffset);
  1150. }
  1151. else
  1152. {
  1153. return parent::start_capture();
  1154. }
  1155. }
  1156. /**
  1157. * Returns the part of the html output that occurred since the call to start_capture
  1158. * and removes this part from the current html output
  1159. * @param $offset mixed The value returned by start_capture
  1160. * @return string The part of the html output that was added since the call to start_capture
  1161. */
  1162. public function end_capture($offset)
  1163. {
  1164. if (is_array($offset))
  1165. {
  1166. if ($this->m_oTabs->TabExists($offset['tc'], $offset['tab']))
  1167. {
  1168. $sCaptured = $this->m_oTabs->TruncateTab($offset['tc'], $offset['tab'], $offset['offset']);
  1169. }
  1170. else
  1171. {
  1172. $sCaptured = '';
  1173. }
  1174. }
  1175. else
  1176. {
  1177. $sCaptured = parent::end_capture($offset);
  1178. }
  1179. return $sCaptured;
  1180. }
  1181. /**
  1182. * Set the message to be displayed in the 'admin-banner' section at the top of the page
  1183. */
  1184. public function SetMessage($sMessage)
  1185. {
  1186. $this->m_sMessage = $sMessage;
  1187. }
  1188. }