itopwebpage.class.inc.php 49 KB

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