itopwebpage.class.inc.php 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Class iTopWebPage
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  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
  31. {
  32. private $m_sMenu;
  33. // private $m_currentOrganization;
  34. private $m_aTabs;
  35. private $m_sCurrentTabContainer;
  36. private $m_sCurrentTab;
  37. private $m_sMessage;
  38. private $m_sInitScript;
  39. public function __construct($sTitle)
  40. {
  41. parent::__construct($sTitle);
  42. ApplicationContext::SetUrlMakerClass('iTopStandardURLMaker');
  43. $this->m_sCurrentTabContainer = '';
  44. $this->m_sCurrentTab = '';
  45. $this->m_aTabs = array();
  46. $this->m_sMenu = "";
  47. $this->m_sMessage = '';
  48. $this->SetRootUrl(utils::GetAbsoluteUrlAppRoot());
  49. $this->add_header("Content-type: text/html; charset=utf-8");
  50. $this->add_header("Cache-control: no-cache");
  51. $this->add_linked_stylesheet("../css/jquery.treeview.css");
  52. $this->add_linked_stylesheet("../css/jquery.autocomplete.css");
  53. $this->add_linked_stylesheet("../css/fg.menu.css");
  54. $this->add_linked_script('../js/jquery.layout.min.js');
  55. $this->add_linked_script('../js/jquery.ba-bbq.min.js');
  56. $this->add_linked_script("../js/jquery.treeview.js");
  57. $this->add_linked_script("../js/jquery.autocomplete.js");
  58. $this->add_linked_script("../js/jquery.positionBy.js");
  59. $this->add_linked_script("../js/jquery.popupmenu.js");
  60. $this->add_linked_script("../js/date.js");
  61. $this->add_linked_script("../js/jquery.blockUI.js");
  62. $this->add_linked_script("../js/utils.js");
  63. $this->add_linked_script("../js/swfobject.js");
  64. $this->add_linked_script("../js/ckeditor/ckeditor.js");
  65. $this->add_linked_script("../js/ckeditor/adapters/jquery.js");
  66. $this->add_linked_script("../js/jquery.qtip-1.0.min.js");
  67. $this->add_linked_script('../js/property_field.js');
  68. $this->add_linked_script('../js/fg.menu.js');
  69. $this->add_linked_script('../js/icon_select.js');
  70. $this->add_linked_script('../js/raphael-min.js');
  71. $this->add_linked_script('../js/g.raphael.js');
  72. $this->add_linked_script('../js/g.pie.js');
  73. $this->add_linked_script('../js/g.dot.js');
  74. $this->add_linked_script('../js/charts.js');
  75. $this->m_sInitScript =
  76. <<< EOF
  77. try
  78. {
  79. var myLayout; // a var is required because this page utilizes: myLayout.allowOverflow() method
  80. // Layout
  81. paneSize = GetUserPreference('menu_size', 300)
  82. myLayout = $('body').layout({
  83. west : {
  84. minSize: 200, size: paneSize, spacing_open: 16, spacing_close: 16, slideTrigger_open: "mouseover", hideTogglerOnSlide: true,
  85. onclose_end: function(name, elt, state, options, layout)
  86. {
  87. if (state.isSliding == false)
  88. {
  89. SetUserPreference('menu_pane', 'closed', true);
  90. }
  91. },
  92. onresize_end: function(name, elt, state, options, layout)
  93. {
  94. if (state.isSliding == false)
  95. {
  96. SetUserPreference('menu_size', state.size, true);
  97. }
  98. },
  99. onopen_end: function(name, elt, state, options, layout)
  100. {
  101. if (state.isSliding == false)
  102. {
  103. SetUserPreference('menu_pane', 'open', true);
  104. }
  105. }
  106. },
  107. center: {
  108. onresize_end: function(name, elt, state, options, layout)
  109. {
  110. $('.v-resizable').each( function() {
  111. var fixedWidth = $(this).parent().innerWidth() - 6;
  112. $(this).width(fixedWidth);
  113. // Make sure it cannot be resized horizontally
  114. $(this).resizable('options', { minWidth: fixedWidth, maxWidth: fixedWidth });
  115. // Now adjust all the child 'items'
  116. var innerWidth = $(this).innerWidth() - 10;
  117. $(this).find('.item').width(innerWidth);
  118. });
  119. }
  120. }
  121. });
  122. myLayout.addPinBtn( "#tPinMenu", "west" );
  123. //myLayout.open( "west" );
  124. $('.ui-layout-resizer-west .ui-layout-toggler').css({background: 'transparent'});
  125. if (GetUserPreference('menu_pane', 'open') == 'closed')
  126. {
  127. myLayout.close('west');
  128. }
  129. $('#left-pane').layout({ resizable: false, spacing_open: 0, south: { size: 94 }});
  130. // Accordion Menu
  131. $("#accordion").accordion({ header: "h3", navigation: true, autoHeight: false, collapsible: false, icons: false }); // collapsible will be enabled once the item will be selected
  132. // Tabs, using JQuery BBQ to store the history
  133. // The "tab widgets" to handle.
  134. var tabs = $('div[id^=tabbedContent]');
  135. // This selector will be reused when selecting actual tab widget A elements.
  136. var tab_a_selector = 'ul.ui-tabs-nav a';
  137. // Enable tabs on all tab widgets. The `event` property must be overridden so
  138. // that the tabs aren't changed on click, and any custom event name can be
  139. // specified. Note that if you define a callback for the 'select' event, it
  140. // will be executed for the selected tab whenever the hash changes.
  141. tabs.tabs({ event: 'change', 'show': function(event, ui) {
  142. $('.resizable', ui.panel).resizable(); // Make resizable everything that claims to be resizable !
  143. }
  144. });
  145. $('.resizable').filter(':visible').resizable();
  146. }
  147. catch(err)
  148. {
  149. // Do something with the error !
  150. alert(err);
  151. }
  152. EOF
  153. ;
  154. $this->add_ready_script(
  155. <<< EOF
  156. // Adjust initial size
  157. $('.v-resizable').each( function()
  158. {
  159. var parent_id = $(this).parent().id;
  160. // Restore the saved height
  161. var iHeight = GetUserPreference(parent_id+'_'+this.id+'_height', undefined);
  162. if (iHeight != undefined)
  163. {
  164. $(this).height(parseInt(iHeight, 10)); // Parse in base 10 !);
  165. }
  166. // Adjust the child 'item''s height and width to fit
  167. var container = $(this);
  168. var fixedWidth = container.parent().innerWidth() - 6;
  169. // Set the width to fit the parent
  170. $(this).width(fixedWidth);
  171. var headerHeight = $(this).find('.drag_handle').height();
  172. // Now adjust the width and height of the child 'item'
  173. container.find('.item').height(container.innerHeight() - headerHeight - 12).width(fixedWidth - 10);
  174. }
  175. );
  176. // Make resizable, vertically only everything that claims to be v-resizable !
  177. $('.v-resizable').resizable( { handles: 's', minHeight: $(this).find('.drag_handle').height(), minWidth: $(this).parent().innerWidth() - 6, maxWidth: $(this).parent().innerWidth() - 6, stop: function()
  178. {
  179. // Adjust the content
  180. var container = $(this);
  181. var headerHeight = $(this).find('.drag_handle').height();
  182. container.find('.item').height(container.innerHeight() - headerHeight - 12);//.width(container.innerWidth());
  183. var parent_id = $(this).parent().id;
  184. SetUserPreference(parent_id+'_'+this.id+'_height', $(this).height(), true); // true => persistent
  185. }
  186. } );
  187. // Tabs, using JQuery BBQ to store the history
  188. // The "tab widgets" to handle.
  189. var tabs = $('div[id^=tabbedContent]');
  190. // This selector will be reused when selecting actual tab widget A elements.
  191. var tab_a_selector = 'ul.ui-tabs-nav a';
  192. // Define our own click handler for the tabs, overriding the default.
  193. tabs.find( tab_a_selector ).click(function()
  194. {
  195. var state = {};
  196. // Get the id of this tab widget.
  197. var id = $(this).closest( 'div[id^=tabbedContent]' ).attr( 'id' );
  198. // Get the index of this tab.
  199. var idx = $(this).parent().prevAll().length;
  200. // Set the state!
  201. state[ id ] = idx;
  202. $.bbq.pushState( state );
  203. });
  204. // Bind an event to window.onhashchange that, when the history state changes,
  205. // iterates over all tab widgets, changing the current tab as necessary.
  206. $(window).bind( 'hashchange', function(e)
  207. {
  208. // Iterate over all tab widgets.
  209. tabs.each(function()
  210. {
  211. // Get the index for this tab widget from the hash, based on the
  212. // appropriate id property. In jQuery 1.4, you should use e.getState()
  213. // instead of $.bbq.getState(). The second, 'true' argument coerces the
  214. // string value to a number.
  215. var idx = $.bbq.getState( this.id, true ) || 0;
  216. // Select the appropriate tab for this tab widget by triggering the custom
  217. // event specified in the .tabs() init above (you could keep track of what
  218. // tab each widget is on using .data, and only select a tab if it has
  219. // changed).
  220. $(this).find( tab_a_selector ).eq( idx ).triggerHandler( 'change' );
  221. });
  222. // Iterate over all truncated lists to find whether they are expanded or not
  223. $('a.truncated').each(function()
  224. {
  225. var state = $.bbq.getState( this.id, true ) || 'close';
  226. if (state == 'open')
  227. {
  228. $(this).trigger('open');
  229. }
  230. else
  231. {
  232. $(this).trigger('close');
  233. }
  234. });
  235. });
  236. // Shortcut menu actions
  237. $('.actions_button a').click( function() {
  238. aMatches = /#(.*)$/.exec(window.location.href);
  239. if (aMatches != null)
  240. {
  241. currentHash = aMatches[1];
  242. if ( /#(.*)$/.test(this.href))
  243. {
  244. this.href = this.href.replace(/#(.*)$/, '#'+currentHash);
  245. }
  246. }
  247. });
  248. // End of Tabs handling
  249. $(".date-pick").datepicker({
  250. showOn: 'button',
  251. buttonImage: '../images/calendar.png',
  252. buttonImageOnly: true,
  253. dateFormat: 'yy-mm-dd',
  254. constrainInput: false,
  255. changeMonth: true,
  256. changeYear: true
  257. });
  258. $(".datetime-pick").datepicker({
  259. showOn: 'button',
  260. buttonImage: '../images/calendar.png',
  261. buttonImageOnly: true,
  262. dateFormat: 'yy-mm-dd 00:00:00',
  263. constrainInput: false,
  264. changeMonth: true,
  265. changeYear: true
  266. });
  267. // Restore the persisted sortable order, for all sortable lists... if any
  268. $('.sortable').each(function()
  269. {
  270. var sTemp = GetUserPreference(this.id+'_order', undefined);
  271. if (sTemp != undefined)
  272. {
  273. var aSerialized = sTemp.split(',');
  274. var sortable = $(this);
  275. $.each(aSerialized, function(i,v) {
  276. var item = $('#menu_'+v);
  277. if (item.length > 0) // Check that the menu exists
  278. {
  279. sortable.append(item);
  280. }
  281. });
  282. }
  283. });
  284. // Make sortable, everything that claims to be sortable
  285. $('.sortable').sortable( {axis: 'y', cursor: 'move', handle: '.drag_handle', stop: function()
  286. {
  287. if ($(this).hasClass('persistent'))
  288. {
  289. // remember the sort order for next time the page is loaded...
  290. sSerialized = $(this).sortable('serialize', {key: 'menu'});
  291. var sTemp = sSerialized.replace(/menu=/g, '');
  292. SetUserPreference(this.id+'_order', sTemp.replace(/&/g, ','), true); // true => persistent !
  293. }
  294. }
  295. });
  296. docWidth = $(document).width();
  297. $('#ModalDlg').dialog({ autoOpen: false, modal: true, width: 0.8*docWidth }); // JQuery UI dialogs
  298. ShowDebug();
  299. $('#logOffBtn>ul').popupmenu();
  300. $('.caselog_header').click( function () { $(this).toggleClass('open').next('.caselog_entry').toggle(); });
  301. EOF
  302. );
  303. $sUserPrefs = appUserPreferences::GetAsJSON();
  304. $this->add_script(
  305. <<<EOF
  306. // // for JQuery history
  307. // function history_callback(hash)
  308. // {
  309. // // do stuff that loads page content based on hash variable
  310. // var aMatches = /^tab_(.*)$/.exec(hash);
  311. // if (aMatches != null)
  312. // {
  313. // var tab = $('#'+hash);
  314. // tab.parents('div[id^=tabbedContent]:first').tabs('select', aMatches[1]);
  315. // }
  316. // }
  317. function goBack()
  318. {
  319. window.history.back();
  320. }
  321. function BackToDetails(sClass, id, sDefaultUrl)
  322. {
  323. window.bInCancel = true;
  324. if (id > 0)
  325. {
  326. window.location.href = AddAppContext(GetAbsoluteUrlAppRoot()+'pages/UI.php?operation=details&class='+sClass+'&id='+id);
  327. }
  328. else
  329. {
  330. window.location.href = sDefaultUrl; // Already contains the context...
  331. }
  332. }
  333. function BackToList(sClass)
  334. {
  335. window.location.href = AddAppContext(GetAbsoluteUrlAppRoot()+'pages/UI.php?operation=search_oql&oql_class='+sClass+'&oql_clause=WHERE id=0');
  336. }
  337. function ShowDebug()
  338. {
  339. if ($('#rawOutput > div').html() != '')
  340. {
  341. $('#rawOutput').dialog( {autoOpen: true, modal:false});
  342. }
  343. }
  344. var oUserPreferences = $sUserPrefs;
  345. // For disabling the CKEditor at init time when the corresponding textarea is disabled !
  346. CKEDITOR.plugins.add( 'disabler',
  347. {
  348. init : function( editor )
  349. {
  350. editor.on( 'instanceReady', function(e)
  351. {
  352. e.removeListener();
  353. $('#'+ editor.name).trigger('update');
  354. });
  355. }
  356. });
  357. EOF
  358. );
  359. // Build menus from module handlers
  360. //
  361. foreach(get_declared_classes() as $sPHPClass)
  362. {
  363. if (is_subclass_of($sPHPClass, 'ModuleHandlerAPI'))
  364. {
  365. $aCallSpec = array($sPHPClass, 'OnMenuCreation');
  366. call_user_func($aCallSpec);
  367. }
  368. }
  369. }
  370. public function AddToMenu($sHtml)
  371. {
  372. $this->m_sMenu .= $sHtml;
  373. }
  374. public function GetSiloSelectionForm()
  375. {
  376. // List of visible Organizations
  377. $iCount = 0;
  378. $oSet = null;
  379. if (MetaModel::IsValidClass('Organization'))
  380. {
  381. // Display the list of *favorite* organizations... but keeping in mind what is the real number of organizations
  382. $aFavoriteOrgs = appUserPreferences::GetPref('favorite_orgs', null);
  383. $oSearchFilter = new DBObjectSearch('Organization');
  384. $oSearchFilter->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', true);
  385. $oSet = new CMDBObjectSet($oSearchFilter);
  386. $iCount = $oSet->Count(); // total number of existing Orgs
  387. // Now get the list of Orgs to be displayed in the menu
  388. $oSearchFilter = DBObjectSearch::FromOQL(ApplicationMenu::GetFavoriteSiloQuery());
  389. $oSearchFilter->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', true);
  390. if (!empty($aFavoriteOrgs))
  391. {
  392. $oSearchFilter->AddCondition('id', $aFavoriteOrgs, 'IN');
  393. }
  394. $oSet = new CMDBObjectSet($oSearchFilter); // List of favorite orgs
  395. }
  396. switch($iCount)
  397. {
  398. case 0:
  399. // No such dimension/silo => nothing to select
  400. $sHtml = '<div id="SiloSelection"><!-- nothing to select --></div>';
  401. break;
  402. case 1:
  403. // Only one possible choice... no selection, but display the value
  404. $oOrg = $oSet->Fetch();
  405. $sHtml = '<div id="SiloSelection">'.$oOrg->GetName().'</div>';
  406. $sHtml .= '';
  407. break;
  408. default:
  409. $sHtml = '';
  410. $oAppContext = new ApplicationContext();
  411. $iCurrentOrganization = $oAppContext->GetCurrentValue('org_id');
  412. $sHtml = '<div id="SiloSelection">';
  413. $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();">';
  414. $sFavoriteOrgs = '';
  415. $oWidget = new UIExtKeyWidget('Organization', 'org_id', '', true /* search mode */);
  416. $sHtml .= $oWidget->Display($this, 50, false, '', $oSet, $iCurrentOrganization, 'org_id', false, 'c[org_id]', '', array('iFieldSize' => 20, 'iMinChars' => MetaModel::GetConfig()->Get('min_autocomplete_chars'), 'sDefaultValue' => Dict::S('UI:AllOrganizations')));
  417. $this->add_ready_script('$("#org_id").bind("extkeychange", function() { $("#SiloSelection form").submit(); } )');
  418. $this->add_ready_script("$('#label_org_id').click( function() { $(this).val(''); $('#org_id').val(''); return true; } );\n");
  419. // Add other dimensions/context information to this form
  420. $oAppContext->Reset('org_id'); // org_id is handled above and we want to be able to change it here !
  421. $oAppContext->Reset('menu'); // don't pass the menu, since a menu may expect more parameters
  422. $sHtml .= $oAppContext->GetForForm(); // Pass what remains, if anything...
  423. $sHtml .= '</form>';
  424. $sHtml .= '</div>';
  425. }
  426. return $sHtml;
  427. }
  428. public function DisplayMenu()
  429. {
  430. // Display the menu
  431. $oAppContext = new ApplicationContext();
  432. $iAccordionIndex = 0;
  433. ApplicationMenu::DisplayMenu($this, $oAppContext->GetAsHash());
  434. }
  435. /**
  436. * Outputs (via some echo) the complete HTML page by assembling all its elements
  437. */
  438. public function output()
  439. {
  440. $sAbsURLAppRoot = addslashes($this->m_sRootUrl);
  441. //$this->set_base($this->m_sRootUrl.'pages/');
  442. $sForm = $this->GetSiloSelectionForm();
  443. $this->DisplayMenu(); // Compute the menu
  444. // Put here the 'ready scripts' that must be executed after all others
  445. $this->add_ready_script(
  446. <<<EOF
  447. // Since the event is only triggered when the hash changes, we need to trigger
  448. // the event now, to handle the hash the page may have loaded with.
  449. $(window).trigger( 'hashchange' );
  450. // Some table are sort-able, some are not, let's fix this
  451. $('table.listResults').each( function() { FixTableSorter($(this)); } );
  452. EOF
  453. );
  454. if ($this->GetOutputFormat() == 'html')
  455. {
  456. foreach($this->a_headers as $s_header)
  457. {
  458. header($s_header);
  459. }
  460. }
  461. $s_captured_output = ob_get_contents();
  462. ob_end_clean();
  463. $sHtml = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
  464. $sHtml .= "<html>\n";
  465. $sHtml .= "<head>\n";
  466. // Make sure that Internet Explorer renders the page using its latest/highest/greatest standards !
  467. $sHtml .= "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n";
  468. $sHtml .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
  469. $sHtml .= "<title>".htmlentities($this->s_title, ENT_QUOTES, 'UTF-8')."</title>\n";
  470. $sHtml .= $this->get_base_tag();
  471. // Stylesheets MUST be loaded before any scripts otherwise
  472. // jQuery scripts may face some spurious problems (like failing on a 'reload')
  473. foreach($this->a_linked_stylesheets as $a_stylesheet)
  474. {
  475. if ($a_stylesheet['condition'] != "")
  476. {
  477. $sHtml .= "<!--[if {$a_stylesheet['condition']}]>\n";
  478. }
  479. $sHtml .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$a_stylesheet['link']}\" />\n";
  480. if ($a_stylesheet['condition'] != "")
  481. {
  482. $sHtml .= "<![endif]-->\n";
  483. }
  484. }
  485. // special stylesheet for printing, hides the navigation gadgets
  486. $sHtml .= "<link rel=\"stylesheet\" media=\"print\" type=\"text/css\" href=\"../css/print.css\" />\n";
  487. if ($this->GetOutputFormat() == 'html')
  488. {
  489. foreach($this->a_linked_scripts as $s_script)
  490. {
  491. // Make sure that the URL to the script contains the application's version number
  492. // so that the new script do NOT get reloaded from the cache when the application is upgraded
  493. if (strpos($s_script, '?') === false)
  494. {
  495. $s_script .= "?itopversion=".ITOP_VERSION;
  496. }
  497. else
  498. {
  499. $s_script .= "&itopversion=".ITOP_VERSION;
  500. }
  501. $sHtml .= "<script type=\"text/javascript\" src=\"$s_script\"></script>\n";
  502. }
  503. $this->add_script("\$(document).ready(function() {\n{$this->m_sInitScript};\nwindow.setTimeout('onDelayedReady()',10)\n});");
  504. if (count($this->m_aReadyScripts)>0)
  505. {
  506. $this->add_script("\nonDelayedReady = function() {\n".implode("\n", $this->m_aReadyScripts)."\n}\n");
  507. }
  508. if (count($this->a_scripts)>0)
  509. {
  510. $sHtml .= "<script type=\"text/javascript\">\n";
  511. foreach($this->a_scripts as $s_script)
  512. {
  513. $sHtml .= "$s_script\n";
  514. }
  515. $sHtml .= "</script>\n";
  516. }
  517. }
  518. if (count($this->a_styles)>0)
  519. {
  520. $sHtml .= "<style>\n";
  521. foreach($this->a_styles as $s_style)
  522. {
  523. $sHtml .= "$s_style\n";
  524. }
  525. $sHtml .= "</style>\n";
  526. }
  527. $sHtml .= "<link rel=\"search\" type=\"application/opensearchdescription+xml\" title=\"iTop\" href=\"".utils::GetAbsoluteUrlAppRoot()."pages/opensearch.xml.php\" />\n";
  528. $sHtml .= "<link rel=\"shortcut icon\" href=\"".utils::GetAbsoluteUrlAppRoot()."images/favicon.ico\" />\n";
  529. $sHtml .= "</head>\n";
  530. $sHtml .= "<body>\n";
  531. // Render the revision number
  532. if (ITOP_REVISION == '$WCREV$')
  533. {
  534. // This is NOT a version built using the buil system, just display the main version
  535. $sVersionString = Dict::Format('UI:iTopVersion:Short', ITOP_VERSION);
  536. }
  537. else
  538. {
  539. // This is a build made from SVN, let display the full information
  540. $sVersionString = Dict::Format('UI:iTopVersion:Long', ITOP_VERSION, ITOP_REVISION, ITOP_BUILD_DATE);
  541. }
  542. // Render the text of the global search form
  543. $sText = htmlentities(utils::ReadParam('text', '', false, 'raw_data'), ENT_QUOTES, 'UTF-8');
  544. $sOnClick = "";
  545. if (empty($sText))
  546. {
  547. // if no search text is supplied then
  548. // 1) the search text is filled with "your search"
  549. // 2) clicking on it will erase it
  550. $sText = Dict::S("UI:YourSearch");
  551. $sOnClick = " onclick=\"this.value='';this.onclick=null;\"";
  552. }
  553. // Render the tabs in the page (if any)
  554. foreach($this->m_aTabs as $sTabContainerName => $m_aTabs)
  555. {
  556. $sTabs = '';
  557. $container_index = 0;
  558. if (count($m_aTabs) > 0)
  559. {
  560. $sTabs = "<!-- tabs -->\n<div id=\"tabbedContent_{$container_index}\" class=\"light\">\n";
  561. $sTabs .= "<ul>\n";
  562. // Display the unordered list that will be rendered as the tabs
  563. $i = 0;
  564. foreach($m_aTabs as $sTabName => $sTabContent)
  565. {
  566. $sTabs .= "<li><a href=\"#tab_$i\" class=\"tab\"><span>".htmlentities($sTabName, ENT_QUOTES, 'UTF-8')."</span></a></li>\n";
  567. $i++;
  568. }
  569. $sTabs .= "</ul>\n";
  570. // Now add the content of the tabs themselves
  571. $i = 0;
  572. foreach($m_aTabs as $sTabName => $sTabContent)
  573. {
  574. $sTabs .= "<div id=\"tab_$i\">".$sTabContent."</div>\n";
  575. $i++;
  576. }
  577. $sTabs .= "</div>\n<!-- end of tabs-->\n";
  578. }
  579. $this->s_content = str_replace("\$Tabs:$sTabContainerName\$", $sTabs, $this->s_content);
  580. $container_index++;
  581. }
  582. if ($this->GetOutputFormat() == 'html')
  583. {
  584. $sUserName = UserRights::GetUser();
  585. $sIsAdmin = UserRights::IsAdministrator() ? '(Administrator)' : '';
  586. if (UserRights::IsAdministrator())
  587. {
  588. $sLogonMessage = Dict::Format('UI:LoggedAsMessage+Admin', $sUserName);
  589. }
  590. else
  591. {
  592. $sLogonMessage = Dict::Format('UI:LoggedAsMessage', $sUserName);
  593. }
  594. $sLogOffMenu = "<span id=\"logOffBtn\"><ul><li><img src=\"../images/onOffBtn.png\"><ul>";
  595. $sLogOffMenu .= "<li><span>$sLogonMessage</span></li>\n";
  596. $sLogOffMenu .= "<li><a href=\"".utils::GetAbsoluteUrlAppRoot()."pages/preferences.php\">".Dict::S('UI:Preferences')."</a></li>\n";
  597. if (utils::CanLogOff())
  598. {
  599. //$sLogOffMenu .= "<li><a href=\"../pages/UI.php?loginop=logoff\">".Dict::S('UI:LogOffMenu')."</a></li>\n";
  600. $sLogOffMenu .= "<li><a href=\"".utils::GetAbsoluteUrlAppRoot()."pages/logoff.php\">".Dict::S('UI:LogOffMenu')."</a></li>\n";
  601. }
  602. if (UserRights::CanChangePassword())
  603. {
  604. $sLogOffMenu .= "<li><a href=\"".utils::GetAbsoluteUrlAppRoot()."pages/UI.php?loginop=change_pwd\">".Dict::S('UI:ChangePwdMenu')."</a></li>\n";
  605. }
  606. $sLogOffMenu .= "</ul>\n</li>\n</ul></span>\n";
  607. $sRestrictions = '';
  608. if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE))
  609. {
  610. if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE))
  611. {
  612. $sRestrictions = Dict::S('UI:AccessRO-All');
  613. }
  614. }
  615. elseif (!MetaModel::DBHasAccess(ACCESS_USER_WRITE))
  616. {
  617. $sRestrictions = Dict::S('UI:AccessRO-Users');
  618. }
  619. $sApplicationBanner = '';
  620. if (strlen($sRestrictions) > 0)
  621. {
  622. $sAdminMessage = trim(MetaModel::GetConfig()->Get('access_message'));
  623. $sApplicationBanner .= '<div id="admin-banner">';
  624. $sApplicationBanner .= '<img src="../images/locked.png" style="vertical-align:middle;">';
  625. $sApplicationBanner .= '&nbsp;<b>'.$sRestrictions.'</b>';
  626. if (strlen($sAdminMessage) > 0)
  627. {
  628. $sApplicationBanner .= '&nbsp;<b>'.$sAdminMessage.'</b>';
  629. }
  630. $sApplicationBanner .= '</div>';
  631. }
  632. if(strlen($this->m_sMessage))
  633. {
  634. $sApplicationBanner .= '<div id="admin-banner"><span style="padding:5px;">'.$this->m_sMessage.'<span></div>';
  635. }
  636. $sEnvironment = utils::GetCurrentEnvironment();
  637. $sBackButton = utils::GetEnvironmentBackButton();
  638. if($sEnvironment != 'production')
  639. {
  640. $sEnvLabel = trim(MetaModel::GetConfig()->Get('app_env_label'));
  641. if (strlen($sEnvLabel) == 0)
  642. {
  643. $sEnvLabel = $sEnvironment;
  644. }
  645. $sApplicationBanner .= '<div id="admin-banner"><span style="padding:5px;">'.Dict::Format('UI:ApplicationEnvironment', $sEnvLabel).$sBackButton.'<span></div>';
  646. }
  647. $sOnlineHelpUrl = MetaModel::GetConfig()->Get('online_help');
  648. //$sLogOffMenu = "<span id=\"logOffBtn\" style=\"height:55px;padding:0;margin:0;\"><img src=\"../images/onOffBtn.png\"></span>";
  649. $sHtml .= '<div id="left-pane" class="ui-layout-west">';
  650. $sHtml .= '<!-- Beginning of the left pane -->';
  651. $sHtml .= ' <div class="ui-layout-north">';
  652. $sHtml .= ' <div id="header-logo">';
  653. $sHtml .= ' <div id="top-left"></div><div id="logo"><a href="http://www.combodo.com/itop"><img src="../images/itop-logo.png" title="'.htmlentities($sVersionString, ENT_QUOTES, 'UTF-8').'" style="border:0; margin-top:16px; margin-right:40px;"/></a></div>';
  654. $sHtml .= ' </div>';
  655. $sHtml .= ' <div class="header-menu">';
  656. $sHtml .= ' <div class="icon ui-state-default ui-corner-all"><span id="tPinMenu" class="ui-icon ui-icon-pin-w">pin</span></div>';
  657. $sHtml .= ' <div style="text-align:center;">'.self::FilterXSS($sForm).'</div>';
  658. $sHtml .= ' </div>';
  659. $sHtml .= ' </div>';
  660. $sHtml .= ' <div id="menu" class="ui-layout-center">';
  661. $sHtml .= ' <div id="inner_menu">';
  662. $sHtml .= ' <div id="accordion">';
  663. $sHtml .= self::FilterXSS($this->m_sMenu);
  664. $sHtml .= ' <!-- Beginning of the accordion menu -->';
  665. $sHtml .= ' <!-- End of the accordion menu-->';
  666. $sHtml .= ' </div>';
  667. $sHtml .= ' </div> <!-- /inner menu -->';
  668. $sHtml .= ' </div> <!-- /menu -->';
  669. $sHtml .= ' <div class="footer ui-layout-south"><a href="http://www.combodo.com" title="www.combodo.com" target="_blank"><img src="../images/logo-combodo.png"/></a></div>';
  670. $sHtml .= '<!-- End of the left pane -->';
  671. $sHtml .= '</div>';
  672. $sHtml .= '<div class="ui-layout-center">';
  673. $sHtml .= ' <div id="top-bar" style="width:100%">';
  674. $sHtml .= self::FilterXSS($sApplicationBanner);
  675. $sHtml .= ' <div id="global-search"><form action="'.utils::GetAbsoluteUrlAppRoot().'pages/UI.php"><table><tr><td></td><td id="g-search-input"><input type="text" name="text" value="'.$sText.'"'.$sOnClick.'/></td>';
  676. $sHtml .= '<td><input type="image" src="../images/searchBtn.png"/></a></td>';
  677. $sHtml .= '<td><a style="background:transparent;" href="'.$sOnlineHelpUrl.'" target="_blank"><img style="border:0;padding-left:20px;padding-right:10px;" title="'.Dict::S('UI:Help').'" src="../images/help.png"/></td>';
  678. $sHtml .= '<td style="padding-right:20px;padding-left:10px;">'.self::FilterXSS($sLogOffMenu).'</td><td><input type="hidden" name="operation" value="full_text"/></td></tr></table></form></div>';
  679. //echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="hidden" name="operation" value="full_text"/></td></tr></table></form></div>';
  680. $sHtml .= ' </div>';
  681. $sHtml .= ' <div class="ui-layout-content">';
  682. $sHtml .= ' <!-- Beginning of page content -->';
  683. $sHtml .= self::FilterXSS($this->s_content);
  684. $sHtml .= ' <!-- End of page content -->';
  685. $sHtml .= ' </div>';
  686. $sHtml .= '</div>';
  687. // Add the captured output
  688. if (trim($s_captured_output) != "")
  689. {
  690. $sHtml .= "<div id=\"rawOutput\" title=\"Debug Output\"><div style=\"height:500px; overflow-y:auto;\">".self::FilterXSS($s_captured_output)."</div></div>\n";
  691. }
  692. $sHtml .= "<div id=\"at_the_end\">".self::FilterXSS($this->s_deferred_content)."</div>";
  693. $sHtml .= "<div style=\"display:none\" title=\"ex2\" id=\"ex2\">Please wait...</div>\n"; // jqModal Window
  694. $sHtml .= "<div style=\"display:none\" title=\"dialog\" id=\"ModalDlg\"></div>";
  695. $sHtml .= "<div style=\"display:none\" id=\"ajax_content\"></div>";
  696. }
  697. else
  698. {
  699. $sHtml .= self::FilterXSS($this->s_content);
  700. }
  701. $sHtml .= "</body>\n";
  702. $sHtml .= "</html>\n";
  703. if ($this->GetOutputFormat() == 'html')
  704. {
  705. echo $sHtml;
  706. }
  707. else if ($this->GetOutputFormat() == 'pdf' && $this->IsOutputFormatAvailable('pdf') )
  708. {
  709. require_once(APPROOT.'lib/MPDF/mpdf.php');
  710. $oMPDF = new mPDF('c');
  711. $oMPDF->mirroMargins = false;
  712. if ($this->a_base['href'] != '')
  713. {
  714. $oMPDF->setBasePath($this->a_base['href']); // Seems that the <BASE> tag is not recognized by mPDF...
  715. }
  716. $oMPDF->showWatermarkText = true;
  717. if ($this->GetOutputOption('pdf', 'template_path'))
  718. {
  719. $oMPDF->setImportUse(); // Allow templates
  720. $oMPDF->SetDocTemplate ($this->GetOutputOption('pdf', 'template_path'), 1);
  721. }
  722. $oMPDF->WriteHTML($sHtml);
  723. $sOutputName = $this->s_title.'.pdf';
  724. if ($this->GetOutputOption('pdf', 'output_name'))
  725. {
  726. $sOutputName = $this->GetOutputOption('pdf', 'output_name');
  727. }
  728. $oMPDF->Output($sOutputName, 'I');
  729. }
  730. }
  731. public function AddTabContainer($sTabContainer)
  732. {
  733. $this->m_aTabs[$sTabContainer] = array();
  734. $this->add("\$Tabs:$sTabContainer\$");
  735. }
  736. public function AddToTab($sTabContainer, $sTabLabel, $sHtml)
  737. {
  738. if (!isset($this->m_aTabs[$sTabContainer][$sTabLabel]))
  739. {
  740. // Set the content of the tab
  741. $this->m_aTabs[$sTabContainer][$sTabLabel] = $sHtml;
  742. }
  743. else
  744. {
  745. // Append to the content of the tab
  746. $this->m_aTabs[$sTabContainer][$sTabLabel] .= $sHtml;
  747. }
  748. }
  749. public function SetCurrentTabContainer($sTabContainer = '')
  750. {
  751. $sPreviousTabContainer = $this->m_sCurrentTabContainer;
  752. $this->m_sCurrentTabContainer = $sTabContainer;
  753. return $sPreviousTabContainer;
  754. }
  755. public function SetCurrentTab($sTabLabel = '')
  756. {
  757. $sPreviousTab = $this->m_sCurrentTab;
  758. $this->m_sCurrentTab = $sTabLabel;
  759. return $sPreviousTab;
  760. }
  761. public function GetCurrentTab()
  762. {
  763. return $this->m_sCurrentTab;
  764. }
  765. public function RemoveTab($sTabLabel, $sTabContainer = null)
  766. {
  767. if ($sTabContainer == null)
  768. {
  769. $sTabContainer = $this->m_sCurrentTabContainer;
  770. }
  771. if (isset($this->m_aTabs[$sTabContainer][$sTabLabel]))
  772. {
  773. // Delete the content of the tab
  774. unset($this->m_aTabs[$sTabContainer][$sTabLabel]);
  775. // If we just removed the active tab, let's reset the active tab
  776. if (($this->m_sCurrentTabContainer == $sTabContainer) && ($this->m_sCurrentTab == $sTabLabel))
  777. {
  778. $this->m_sCurrentTab = '';
  779. }
  780. }
  781. }
  782. /**
  783. * Finds the tab whose title matches a given pattern
  784. * @return mixed The name of the tab as a string or false if not found
  785. */
  786. public function FindTab($sPattern, $sTabContainer = null)
  787. {
  788. $return = false;
  789. if ($sTabContainer == null)
  790. {
  791. $sTabContainer = $this->m_sCurrentTabContainer;
  792. }
  793. foreach($this->m_aTabs[$sTabContainer] as $sTabLabel => $void)
  794. {
  795. if (preg_match($sPattern, $sTabLabel))
  796. {
  797. $result = $sTabLabel;
  798. break;
  799. }
  800. }
  801. return $result;
  802. }
  803. /**
  804. * Make the given tab the active one, as if it were clicked
  805. * DOES NOT WORK: apparently in the *old* version of jquery
  806. * that we are using this is not supported... TO DO upgrade
  807. * the whole jquery bundle...
  808. */
  809. public function SelectTab($sTabContainer, $sTabLabel)
  810. {
  811. $container_index = 0;
  812. $tab_index = 0;
  813. foreach($this->m_aTabs as $sCurrentTabContainerName => $aTabs)
  814. {
  815. if ($sTabContainer == $sCurrentTabContainerName)
  816. {
  817. foreach($aTabs as $sCurrentTabLabel => $void)
  818. {
  819. if ($sCurrentTabLabel == $sTabLabel)
  820. {
  821. break;
  822. }
  823. $tab_index++;
  824. }
  825. break;
  826. }
  827. $container_index++;
  828. }
  829. $sSelector = '#tabbedContent_'.$container_index.' > ul';
  830. $this->add_ready_script("$('$sSelector').tabs('select', $tab_index);");
  831. }
  832. public function StartCollapsibleSection($sSectionLabel, $bOpen = false)
  833. {
  834. $this->add($this->GetStartCollapsibleSection($sSectionLabel, $bOpen));
  835. }
  836. public function GetStartCollapsibleSection($sSectionLabel, $bOpen = false)
  837. {
  838. $sHtml = '';
  839. static $iSectionId = 0;
  840. $sImgStyle = $bOpen ? ' open' : '';
  841. $sHtml .= "<a id=\"LnkCollapse_$iSectionId\" class=\"CollapsibleLabel{$sImgStyle}\" href=\"#\">$sSectionLabel</a></br>\n";
  842. $sStyle = $bOpen ? '' : 'style="display:none" ';
  843. $sHtml .= "<div id=\"Collapse_$iSectionId\" $sStyle>";
  844. $this->add_ready_script("\$(\"#LnkCollapse_$iSectionId\").click(function() {\$(\"#Collapse_$iSectionId\").slideToggle('normal'); $(\"#LnkCollapse_$iSectionId\").toggleClass('open');});");
  845. //$this->add_ready_script("$('#LnkCollapse_$iSectionId').hide();");
  846. $iSectionId++;
  847. return $sHtml;
  848. }
  849. public function EndCollapsibleSection()
  850. {
  851. $this->add($this->GetEndCollapsibleSection());
  852. }
  853. public function GetEndCollapsibleSection()
  854. {
  855. return "</div>";
  856. }
  857. public function add($sHtml)
  858. {
  859. if (!empty($this->m_sCurrentTabContainer) && !empty($this->m_sCurrentTab))
  860. {
  861. $this->AddToTab($this->m_sCurrentTabContainer, $this->m_sCurrentTab, $sHtml);
  862. }
  863. else
  864. {
  865. parent::add($sHtml);
  866. }
  867. }
  868. /**
  869. * Records the current state of the 'html' part of the page output
  870. * @return mixed The current state of the 'html' output
  871. */
  872. public function start_capture()
  873. {
  874. if (!empty($this->m_sCurrentTabContainer) && !empty($this->m_sCurrentTab))
  875. {
  876. $iOffset = isset($this->m_aTabs[$this->m_sCurrentTabContainer][$this->m_sCurrentTab]) ? strlen($this->m_aTabs[$this->m_sCurrentTabContainer][$this->m_sCurrentTab]): 0;
  877. return array('tc' => $this->m_sCurrentTabContainer, 'tab' => $this->m_sCurrentTab, 'offset' => $iOffset);
  878. }
  879. else
  880. {
  881. return parent::start_capture();
  882. }
  883. }
  884. /**
  885. * Returns the part of the html output that occurred since the call to start_capture
  886. * and removes this part from the current html output
  887. * @param $offset mixed The value returned by start_capture
  888. * @return string The part of the html output that was added since the call to start_capture
  889. */
  890. public function end_capture($offset)
  891. {
  892. if (is_array($offset))
  893. {
  894. if (isset($this->m_aTabs[$offset['tc']][$offset['tab']]))
  895. {
  896. $sCaptured = substr($this->m_aTabs[$offset['tc']][$offset['tab']], $offset['offset']);
  897. $this->m_aTabs[$offset['tc']][$offset['tab']] = substr($this->m_aTabs[$offset['tc']][$offset['tab']], 0, $offset['offset']);
  898. }
  899. else
  900. {
  901. $sCaptured = '';
  902. }
  903. }
  904. else
  905. {
  906. $sCaptured = parent::end_capture($offset);
  907. }
  908. return $sCaptured;
  909. }
  910. /**
  911. * Set the message to be displayed in the 'admin-banner' section at the top of the page
  912. */
  913. public function SetMessage($sMessage)
  914. {
  915. $this->m_sMessage = $sMessage;
  916. }
  917. }
  918. ?>