itopwebpage.class.inc.php 54 KB

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