itopwebpage.class.inc.php 48 KB

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