itopwebpage.class.inc.php 48 KB

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