itopwebpage.class.inc.php 51 KB

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