itopwebpage.class.inc.php 49 KB

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