itopwebpage.class.inc.php 51 KB

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