itopwebpage.class.inc.php 35 KB

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