itopwebpage.class.inc.php 37 KB

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