itopwebpage.class.inc.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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("../application/nicewebpage.class.inc.php");
  25. require_once("../application/usercontext.class.inc.php");
  26. require_once("../application/applicationcontext.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. public function __construct($sTitle, $currentOrganization)
  38. {
  39. parent::__construct($sTitle);
  40. $this->m_sCurrentTabContainer = '';
  41. $this->m_sCurrentTab = '';
  42. $this->m_aTabs = array();
  43. $this->m_sMenu = "";
  44. $oAppContext = new ApplicationContext();
  45. $sExtraParams = $oAppContext->GetForLink();
  46. $this->m_currentOrganization = $currentOrganization;
  47. $this->add_header("Content-type: text/html; charset=utf-8");
  48. $this->add_header("Cache-control: no-cache");
  49. $this->add_linked_stylesheet("../css/jquery.treeview.css");
  50. $this->add_linked_stylesheet("../css/jquery.autocomplete.css");
  51. // $this->add_linked_stylesheet("../css/date.picker.css");
  52. $this->add_linked_script('../js/jquery.layout.min.js');
  53. // $this->add_linked_script("../js/jquery.dimensions.js");
  54. $this->add_linked_script("../js/jquery.tablehover.js");
  55. $this->add_linked_script("../js/jquery.treeview.js");
  56. $this->add_linked_script("../js/jquery.autocomplete.js");
  57. $this->add_linked_script("../js/jquery.bgiframe.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.date.picker.js");
  62. $this->add_linked_script("../js/jquery.tablesorter.min.js");
  63. $this->add_linked_script("../js/jquery.blockUI.js");
  64. $this->add_linked_script("../js/utils.js");
  65. $this->add_linked_script("../js/swfobject.js");
  66. $this->add_ready_script(
  67. <<<EOF
  68. //add new widget called TruncatedList to properly display truncated lists when they are sorted
  69. $.tablesorter.addWidget({
  70. // give the widget a id
  71. id: "truncatedList",
  72. // format is called when the on init and when a sorting has finished
  73. format: function(table)
  74. {
  75. // Check if there is a "truncated" line
  76. this.truncatedList = false;
  77. if ($("tr td.truncated",table).length > 0)
  78. {
  79. this.truncatedList = true;
  80. }
  81. if (this.truncatedList)
  82. {
  83. $("tr td",table).removeClass('truncated');
  84. $("tr:last td",table).addClass('truncated');
  85. }
  86. }
  87. });
  88. try
  89. {
  90. var myLayout; // a var is required because this page utilizes: myLayout.allowOverflow() method
  91. $(document).ready(function () {
  92. // Layout
  93. myLayout = $('body').layout({
  94. west : { minSize: 200, size: 300 /* TO DO: read from a cookie ?*/, spacing_open: 16, spacing_close: 16, slideTrigger_open: "mouseover", hideTogglerOnSlide: true }
  95. });
  96. myLayout.addPinBtn( "#tPinMenu", "west" );
  97. //myLayout.open( "west" );
  98. $('.ui-layout-resizer-west').html('<img src="../images/splitter-top-corner.png"/>');
  99. // Accordion Menu
  100. $("#accordion").accordion({ header: "h3", navigation: true, autoHeight: false });
  101. });
  102. //$("div[id^=tabbedContent] > ul").tabs( 1, { fxFade: true, fxSpeed: 'fast' } ); // tabs
  103. $("div[id^=tabbedContent]").tabs(); // tabs
  104. $("table.listResults").tableHover(); // hover tables
  105. $(".listResults").tablesorter( { headers: { 0:{sorter: false }}, widgets: ['zebra', 'truncatedList']} ); // sortable and zebra tables
  106. $(".date-pick").datepicker({
  107. showOn: 'button',
  108. buttonImage: '../images/calendar.png',
  109. buttonImageOnly: true,
  110. dateFormat: 'yy-mm-dd',
  111. constrainInput: false,
  112. changeMonth: true,
  113. changeYear: true
  114. });
  115. $('.resizable').resizable(); // Make resizable everything that claims to be resizable !
  116. docWidth = $(document).width();
  117. $('#ModalDlg').dialog({ autoOpen: false, modal: true, width: 0.8*docWidth }); // JQuery UI dialogs
  118. ShowDebug();
  119. $('#logOffBtn>ul').popupmenu();
  120. }
  121. catch(err)
  122. {
  123. // Do something with the error !
  124. }
  125. //$('.display_block').draggable(); // make the blocks draggable
  126. EOF
  127. );
  128. $this->add_script("
  129. // For automplete
  130. function findValue(li) {
  131. if( li == null ) return alert(\"No match!\");
  132. // if coming from an AJAX call, let's use the CityId as the value
  133. if( !!li.extra ) var sValue = li.extra[0];
  134. // otherwise, let's just display the value in the text box
  135. else var sValue = li.selectValue;
  136. //alert(\"The value you selected was: \" + sValue);
  137. }
  138. function selectItem(li) {
  139. findValue(li);
  140. }
  141. function formatItem(row) {
  142. return row[0];
  143. }
  144. function goBack()
  145. {
  146. window.history.back();
  147. }
  148. function BackToDetails(sClass, id)
  149. {
  150. window.location.href = './UI.php?operation=details&class='+sClass+'&id='+id;
  151. }
  152. function ShowDebug()
  153. {
  154. if ($('#rawOutput > div').html() != '')
  155. {
  156. $('#rawOutput').dialog( {autoOpen: true, modal:false});
  157. }
  158. }
  159. ");
  160. // Add the standard menus
  161. /*
  162. * +--------------------+
  163. * | Welcome |
  164. * +--------------------+
  165. * Welcome To iTop
  166. * +--------------------+
  167. * | Tools |
  168. * +--------------------+
  169. * CSV Import
  170. * +--------------------+
  171. * | Admin Tools | << Only present if the user is an admin
  172. * +--------------------+
  173. * User Accounts
  174. * Profiles
  175. * Notifications
  176. * Run Queries
  177. * Export
  178. * Data Model
  179. * Universal Search
  180. */
  181. $oWelcomeMenu = new MenuGroup('UI:WelcomeMenu', 0 /* fRank */);
  182. new TemplateMenuNode('UI:WelcomeMenu', '../business/templates/welcome_menu.html', $oWelcomeMenu->GetIndex() /* oParent */, 1 /* fRank */);
  183. $oToolsMenu = new MenuGroup('UI:AdvancedToolsMenu', 2 /* fRank */);
  184. new WebPageMenuNode('UI:CSVImportMenu', '../pages/csvimport.php', $oToolsMenu->GetIndex(), 1 /* fRank */);
  185. if (userRights::IsAdministrator())
  186. {
  187. // Add the admin menus
  188. $oAdminMenu = new MenuGroup('UI:AdminToolsMenu', 999 /* fRank */);
  189. new OQLMenuNode('UI:UserAccountsMenu', 'UI:UserAccountsMenu:Title', 'SELECT URP_Users', $oAdminMenu->GetIndex(), 1 /* fRank */);
  190. new OQLMenuNode('UI:ProfilesMenu', 'UI:ProfilesMenu:Title', 'SELECT URP_Profiles', $oAdminMenu->GetIndex(), 2 /* fRank */);
  191. new TemplateMenuNode('UI:NotificationsMenu', '../business/templates/notifications_menu.html', $oAdminMenu->GetIndex(), 3 /* fRank */);
  192. new WebPageMenuNode('UI:RunQueriesMenu', '../pages/run_query.php', $oAdminMenu->GetIndex(), 8 /* fRank */);
  193. new WebPageMenuNode('UI:ExportMenu', '../webservices/export.php', $oAdminMenu->GetIndex(), 9 /* fRank */);
  194. new WebPageMenuNode('UI:DataModelMenu', '../pages/schema.php', $oAdminMenu->GetIndex(), 10 /* fRank */);
  195. new WebPageMenuNode('UI:UniversalSearchMenu', '../pages/UniversalSearch.php', $oAdminMenu->GetIndex(), 11 /* fRank */);
  196. }
  197. }
  198. public function AddToMenu($sHtml)
  199. {
  200. $this->m_sMenu .= $sHtml;
  201. }
  202. public function GetSiloSelectionForm()
  203. {
  204. $sHtml = '<div id="SiloSelection">';
  205. $sHtml .= '<form style="display:inline" action="'.$_SERVER['PHP_SELF'].'"><select style="width:150px;font-size:x-small" name="org_id" title="Pick an organization" onChange="this.form.submit();">';
  206. // List of visible Organizations
  207. $oContext = new UserContext();
  208. $oSearchFilter = $oContext->NewFilter("bizOrganization");
  209. $oSet = new CMDBObjectSet($oSearchFilter);
  210. $sSelected = ($this->m_currentOrganization == '') ? ' selected' : '';
  211. $sHtml .= '<option value="">'.Dict::S('UI:AllOrganizations').'</option>';
  212. if ($oSet->Count() > 0)
  213. while($oOrg = $oSet->Fetch())
  214. {
  215. if ($this->m_currentOrganization == $oOrg->GetKey())
  216. {
  217. $oCurrentOrganization = $oOrg;
  218. $sSelected = " selected";
  219. }
  220. else
  221. {
  222. $sSelected = "";
  223. }
  224. $sHtml .= '<option value="'.$oOrg->GetKey().'"'.$sSelected.'>'.$oOrg->Get('name').'</option>';
  225. }
  226. $sHtml .= '</select>';
  227. // Add other dimensions/context information to this form
  228. $oAppContext = new ApplicationContext();
  229. $oAppContext->Reset('org_id'); // Org id is handled above and we want to be able to change it here !
  230. $sHtml .= $oAppContext->GetForForm();
  231. $sHtml .= '</form>';
  232. $sHtml .= '</div>';
  233. return $sHtml;
  234. }
  235. public function DisplayMenu()
  236. {
  237. $oContext = new UserContext();
  238. // Display the menu
  239. $oAppContext = new ApplicationContext();
  240. $iActiveNodeId = ApplicationMenu::GetActiveNodeId();
  241. $iAccordionIndex = 0;
  242. ApplicationMenu::DisplayMenu($this, $oAppContext->GetAsHash(), $iActiveNodeId);
  243. }
  244. /**
  245. * Outputs (via some echo) the complete HTML page by assembling all its elements
  246. */
  247. public function output()
  248. {
  249. $this->DisplayMenu(); // Compute the menu
  250. foreach($this->a_headers as $s_header)
  251. {
  252. header($s_header);
  253. }
  254. $s_captured_output = ob_get_contents();
  255. ob_end_clean();
  256. echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
  257. echo "<html>\n";
  258. echo "<head>\n";
  259. echo "<title>{$this->s_title}</title>\n";
  260. echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
  261. echo $this->get_base_tag();
  262. // Stylesheets MUST be loaded before any scripts otherwise
  263. // jQuery scripts may face some spurious problems (like failing on a 'reload')
  264. foreach($this->a_linked_stylesheets as $a_stylesheet)
  265. {
  266. if ($a_stylesheet['condition'] != "")
  267. {
  268. echo "<!--[if {$a_stylesheet['condition']}]>\n";
  269. }
  270. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$a_stylesheet['link']}\" />\n";
  271. if ($a_stylesheet['condition'] != "")
  272. {
  273. echo "<![endif]-->\n";
  274. }
  275. }
  276. foreach($this->a_linked_scripts as $s_script)
  277. {
  278. echo "<script type=\"text/javascript\" src=\"$s_script\"></script>\n";
  279. }
  280. if (count($this->m_aReadyScripts)>0)
  281. {
  282. $this->add_script("\$(document).ready(function() {\n".implode("\n", $this->m_aReadyScripts)."\n});");
  283. }
  284. if (count($this->a_scripts)>0)
  285. {
  286. echo "<script type=\"text/javascript\">\n";
  287. foreach($this->a_scripts as $s_script)
  288. {
  289. echo "$s_script\n";
  290. }
  291. echo "</script>\n";
  292. }
  293. if (count($this->a_styles)>0)
  294. {
  295. echo "<style>\n";
  296. foreach($this->a_styles as $s_style)
  297. {
  298. echo "$s_style\n";
  299. }
  300. echo "</style>\n";
  301. }
  302. echo "<link rel=\"search\" type=\"application/opensearchdescription+xml\" title=\"iTop\" href=\"./opensearch.xml.php\" />\n";
  303. echo "</head>\n";
  304. echo "<body>\n";
  305. // Render the revision number
  306. if (ITOP_REVISION == '$WCREV$')
  307. {
  308. // This is NOT a version built using the buil system, just display the main version
  309. $sVersionString = "iTop Version ".ITOP_VERSION;
  310. }
  311. else
  312. {
  313. // This is a build made from SVN, let display the full information
  314. $sVersionString = "iTop Version ".ITOP_VERSION." revision ".ITOP_REVISION.", built on: ".ITOP_BUILD_DATE;
  315. }
  316. // Render the text of the global search form
  317. $sText = Utils::ReadParam('text', '');
  318. $sOnClick = "";
  319. if (empty($sText))
  320. {
  321. // if no search text is supplied then
  322. // 1) the search text is filled with "your search"
  323. // 2) clicking on it will erase it
  324. $sText = Dict::S("UI:YourSearch");
  325. $sOnClick = " onclick=\"this.value='';this.onclick=null;\"";
  326. }
  327. $sForm = $this->GetSiloSelectionForm();
  328. // Render the tabs in the page (if any)
  329. foreach($this->m_aTabs as $sTabContainerName => $m_aTabs)
  330. {
  331. $sTabs = '';
  332. $container_index = 0;
  333. if (count($m_aTabs) > 0)
  334. {
  335. $sTabs = "<!-- tabs -->\n<div id=\"tabbedContent_{$container_index}\" class=\"light\">\n";
  336. $sTabs .= "<ul>\n";
  337. // Display the unordered list that will be rendered as the tabs
  338. $i = 0;
  339. foreach($m_aTabs as $sTabName => $sTabContent)
  340. {
  341. $sTabs .= "<li><a href=\"#fragment_$i\" class=\"tab\"><span>".htmlentities($sTabName, ENT_QUOTES, 'UTF-8')."</span></a></li>\n";
  342. $i++;
  343. }
  344. $sTabs .= "</ul>\n";
  345. // Now add the content of the tabs themselves
  346. $i = 0;
  347. foreach($m_aTabs as $sTabName => $sTabContent)
  348. {
  349. $sTabs .= "<div id=\"fragment_$i\">".$sTabContent."</div>\n";
  350. $i++;
  351. }
  352. $sTabs .= "</div>\n<!-- end of tabs-->\n";
  353. }
  354. $this->s_content = str_replace("\$Tabs:$sTabContainerName\$", $sTabs, $this->s_content);
  355. $container_index++;
  356. }
  357. $sUserName = UserRights::GetUser();
  358. $sIsAdmin = UserRights::IsAdministrator() ? '(Administrator)' : '';
  359. if (UserRights::IsAdministrator())
  360. {
  361. $sLogonMessage = Dict::Format('UI:LoggedAsMessage+Admin', $sUserName);
  362. }
  363. else
  364. {
  365. $sLogonMessage = Dict::Format('UI:LoggedAsMessage', $sUserName);
  366. }
  367. $sLogOffMenu = "<span id=\"logOffBtn\"><ul><li><img src=\"../images/onOffBtn.png\"><ul>";
  368. $sLogOffMenu .= "<li><span>$sLogonMessage</span></li>\n";
  369. $sLogOffMenu .= "<li><a href=\"#\">Log Off</a></li>\n";
  370. $sLogOffMenu .= "<li><a href=\"#\">Change password...</a></li>\n";
  371. $sLogOffMenu .= "</ul>\n</li>\n</ul></span>\n";
  372. //$sLogOffMenu = "<span id=\"logOffBtn\" style=\"height:55px;padding:0;margin:0;\"><img src=\"../images/onOffBtn.png\"></span>";
  373. echo '<div id="left-pane" class="ui-layout-west">';
  374. echo '<!-- Beginning of the left pane -->';
  375. echo ' <div id="header-logo">';
  376. echo ' <div id="top-left"></div><div id="logo"><img src="../images/itop-logo.png" style="margin-top:16px; margin-right:40px;"/></div>';
  377. echo ' </div>';
  378. echo ' <div class="header-menu">';
  379. echo ' <div class="icon ui-state-default ui-corner-all"><span id="tPinMenu" class="ui-icon ui-icon-pin-w">pin</span></div>';
  380. echo ' <div style="width:100%; text-align:center;">'.$sForm.'</div>';
  381. echo ' </div>';
  382. echo ' <div id="menu" class="ui-layout-content">';
  383. echo ' <div id="inner_menu">';
  384. echo ' <div id="accordion">';
  385. echo $this->m_sMenu;
  386. echo ' <!-- Beginning of the accordion menu -->';
  387. echo ' <!-- End of the accordion menu-->';
  388. echo ' </div>';
  389. echo ' </div> <!-- /inner menu -->';
  390. echo ' </div> <!-- /menu -->';
  391. echo ' <div class="footer"><span>iTop by Combodo</span></div>';
  392. echo '<!-- End of the left pane -->';
  393. echo '</div>';
  394. echo '<div class="ui-layout-center">';
  395. echo ' <div id="top-bar" style="width:100%">';
  396. echo ' <div id="global-search"><form><table><tr><td id="g-search-input"><input type="text" name="text" value="'.$sText.'"'.$sOnClick.'/></td>';
  397. echo '<td><input type="image" src="../images/searchBtn.png"/></td>';
  398. echo '<td style="padding-right:20px;padding-left:20px;">'.$sLogOffMenu.'</td><td><input type="hidden" name="operation" value="full_text"/></td></tr></table></form></div>';
  399. //echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="hidden" name="operation" value="full_text"/></td></tr></table></form></div>';
  400. echo ' </div>';
  401. echo ' <div class="ui-layout-content">';
  402. echo ' <!-- Beginning of page content -->';
  403. echo $this->s_content;
  404. echo ' <!-- End of page content -->';
  405. echo ' </div>';
  406. echo '</div>';
  407. /*
  408. echo "<div class=\"iTopLogo\" title=\"$sVersionString\"><span>iTop</span></div>\n";
  409. //echo "<div id=\"GlobalSearch\"><div style=\"border: 1px solid #999; padding:1px; background-color:#fff;\"><img src=\"../images/magnifier.gif\"/><input style=\"border:0\" type=\"text\" size=\"15\" title=\"Global Search\"></input></div></div>\n";
  410. $sText = Utils::ReadParam('text', '');
  411. $sOnClick = "";
  412. if (empty($sText))
  413. {
  414. // if no search text is supplied then
  415. // 1) the search text is filled with "your search"
  416. // 2) clicking on it will erase it
  417. $sText = Dict::S("UI:YourSearch");
  418. $sOnClick = " onclick=\"this.value='';this.onclick=null;\"";
  419. }
  420. $sUserName = UserRights::GetUser();
  421. $sIsAdmin = UserRights::IsAdministrator() ? '(Administrator)' : '';
  422. if (UserRights::IsAdministrator())
  423. {
  424. $sLogonMessage = Dict::Format('UI:LoggedAsMessage+Admin', $sUserName);
  425. }
  426. else
  427. {
  428. $sLogonMessage = Dict::Format('UI:LoggedAsMessage', $sUserName);
  429. }
  430. $sLogOffBtn = Dict::S('UI:Button:Logoff');
  431. $sSearchBtn = Dict::S('UI:Button:GlobalSearch');
  432. echo "<div id=\"Login\" style=\"position:absolute; top:18px; right:16px; width:600px;\">{$sLogonMessage}&nbsp;&nbsp;";
  433. echo "<form action=\"../pages/UI.php\" method=\"post\" style=\"display:inline\">\n";
  434. echo "<input type=\"submit\" value=\"$sLogOffBtn\" />\n";
  435. echo "<input type=\"hidden\" name=\"loginop\" value=\"logoff\" />\n";
  436. echo "</form>\n";
  437. echo "<form action=\"../pages/UI.php\" style=\"display:inline\"><div style=\"padding:1px; background-color:#fff;display:inline;\"><img src=\"../images/magnifier.gif\"/><input style=\"border:0\" type=\"text\" size=\"15\" title=\"Global Search\" name=\"text\" value=\"$sText\"$sOnClick></input></div><input type=\"submit\" value=\"$sSearchBtn\" />
  438. <input type=\"hidden\" name=\"operation\" value=\"full_text\" /></form>\n";
  439. echo "</div>\n";
  440. echo "</div>\n";
  441. // Display the menu
  442. echo "<div id=\"MySplitter\">\n";
  443. echo " <div id=\"LeftPane\">\n";
  444. echo $this->m_sMenu;
  445. echo " </div> <!-- LeftPane -->\n";
  446. echo "<div id=\"RightPane\">\n";
  447. // Display the page's content
  448. echo $this->s_content;
  449. */
  450. // Add the captured output
  451. if (trim($s_captured_output) != "")
  452. {
  453. echo "<div id=\"rawOutput\" title=\"Debug Output\"><div style=\"height:500px; overflow-y:auto;\">$s_captured_output</div></div>\n";
  454. }
  455. echo $this->s_deferred_content;
  456. echo "<div style=\"display:none\" title=\"ex2\" id=\"ex2\">Please wait...</div>\n"; // jqModal Window
  457. echo "<div style=\"display:none\" title=\"dialog\" id=\"ModalDlg\"></div>";
  458. echo "</body>\n";
  459. echo "</html>\n";
  460. }
  461. public function AddTabContainer($sTabContainer)
  462. {
  463. $this->m_aTabs[$sTabContainer] = array();
  464. $this->add("\$Tabs:$sTabContainer\$");
  465. }
  466. public function AddToTab($sTabContainer, $sTabLabel, $sHtml)
  467. {
  468. if (!isset($this->m_aTabs[$sTabContainer][$sTabLabel]))
  469. {
  470. // Set the content of the tab
  471. $this->m_aTabs[$sTabContainer][$sTabLabel] = $sHtml;
  472. }
  473. else
  474. {
  475. // Append to the content of the tab
  476. $this->m_aTabs[$sTabContainer][$sTabLabel] .= $sHtml;
  477. }
  478. }
  479. public function SetCurrentTabContainer($sTabContainer = '')
  480. {
  481. $sPreviousTabContainer = $this->m_sCurrentTabContainer;
  482. $this->m_sCurrentTabContainer = $sTabContainer;
  483. return $sPreviousTabContainer;
  484. }
  485. public function SetCurrentTab($sTabLabel = '')
  486. {
  487. $sPreviousTab = $this->m_sCurrentTab;
  488. $this->m_sCurrentTab = $sTabLabel;
  489. return $sPreviousTab;
  490. }
  491. /**
  492. * Make the given tab the active one, as if it were clicked
  493. * DOES NOT WORK: apparently in the *old* version of jquery
  494. * that we are using this is not supported... TO DO upgrade
  495. * the whole jquery bundle...
  496. */
  497. public function SelectTab($sTabContainer, $sTabLabel)
  498. {
  499. $container_index = 0;
  500. $tab_index = 0;
  501. foreach($this->m_aTabs as $sCurrentTabContainerName => $aTabs)
  502. {
  503. if ($sTabContainer == $sCurrentTabContainerName)
  504. {
  505. foreach($aTabs as $sCurrentTabLabel => $void)
  506. {
  507. if ($sCurrentTabLabel == $sTabLabel)
  508. {
  509. break;
  510. }
  511. $tab_index++;
  512. }
  513. break;
  514. }
  515. $container_index++;
  516. }
  517. $sSelector = '#tabbedContent_'.$container_index.' > ul';
  518. $this->add_ready_script("$('$sSelector').tabs('select', $tab_index);");
  519. }
  520. public function StartCollapsibleSection($sSectionLabel, $bOpen = false)
  521. {
  522. $this->add($this->GetStartCollapsibleSection($sSectionLabel, $bOpen));
  523. }
  524. public function GetStartCollapsibleSection($sSectionLabel, $bOpen = false)
  525. {
  526. $sHtml = '';
  527. static $iSectionId = 0;
  528. $sImgStyle = $bOpen ? ' open' : '';
  529. $sHtml .= "<a id=\"LnkCollapse_$iSectionId\" class=\"CollapsibleLabel{$sImgStyle}\" href=\"#\">$sSectionLabel</a></br>\n";
  530. $sStyle = $bOpen ? '' : 'style="display:none" ';
  531. $sHtml .= "<div id=\"Collapse_$iSectionId\" $sStyle>";
  532. $this->add_ready_script("\$(\"#LnkCollapse_$iSectionId\").click(function() {\$(\"#Collapse_$iSectionId\").slideToggle('normal'); $(\"#LnkCollapse_$iSectionId\").toggleClass('open');});");
  533. //$this->add_ready_script("$('#LnkCollapse_$iSectionId').hide();");
  534. $iSectionId++;
  535. return $sHtml;
  536. }
  537. public function EndCollapsibleSection()
  538. {
  539. $this->add($this->GetEndCollapsibleSection());
  540. }
  541. public function GetEndCollapsibleSection()
  542. {
  543. return "</div>";
  544. }
  545. public function add($sHtml)
  546. {
  547. if (!empty($this->m_sCurrentTabContainer) && !empty($this->m_sCurrentTab))
  548. {
  549. $this->AddToTab($this->m_sCurrentTabContainer, $this->m_sCurrentTab, $sHtml);
  550. }
  551. else
  552. {
  553. parent::add($sHtml);
  554. }
  555. }
  556. /*
  557. public function AddSearchForm($sClassName, $bOpen = false)
  558. {
  559. $iSearchSectionId = 0;
  560. $sStyle = $bOpen ? 'SearchDrawer' : 'SearchDrawer DrawerClosed';
  561. $this->add("<div id=\"Search_$iSearchSectionId\" class=\"$sStyle\">\n");
  562. $this->add("<h1>Search form for ".Metamodel::GetName($sClassName)."</h1>\n");
  563. $this->add_ready_script("\$(\"#LnkSearch_$iSearchSectionId\").click(function() {\$(\"#Search_$iSearchSectionId\").slideToggle('normal'); $(\"#LnkSearch_$iSearchSectionId\").toggleClass('open');});");
  564. $oFilter = new DBObjectSearch($sClassName);
  565. $sFilter = $oFilter->serialize();
  566. $oSet = new CMDBObjectSet($oFilter);
  567. cmdbAbstractObject::DisplaySearchForm($this, $oSet, array('operation' => 'search', 'filter' => $sFilter, 'search_form' => true));
  568. $this->add("</div>\n");
  569. $this->add("<div class=\"HRDrawer\"/></div>\n");
  570. $this->add("<div id=\"LnkSearch_$iSearchSectionId\" class=\"DrawerHandle\">Search</div>\n");
  571. $iSearchSectionId++;
  572. }
  573. */
  574. }
  575. ?>