itopwebpage.class.inc.php 53 KB

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