itopwebpage.class.inc.php 52 KB

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