itopwebpage.class.inc.php 48 KB

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