itopwebpage.class.inc.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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. $this->DisplayMenu();
  161. }
  162. public function AddToMenu($sHtml)
  163. {
  164. $this->m_sMenu .= $sHtml;
  165. }
  166. public function GetSiloSelectionForm()
  167. {
  168. $sHtml = '<div id="SiloSelection">';
  169. $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();">';
  170. // List of visible Organizations
  171. $oContext = new UserContext();
  172. $oSearchFilter = $oContext->NewFilter("bizOrganization");
  173. $oSet = new CMDBObjectSet($oSearchFilter);
  174. $sSelected = ($this->m_currentOrganization == '') ? ' selected' : '';
  175. $sHtml .= '<option value="">'.Dict::S('UI:AllOrganizations').'</option>';
  176. if ($oSet->Count() > 0)
  177. while($oOrg = $oSet->Fetch())
  178. {
  179. if ($this->m_currentOrganization == $oOrg->GetKey())
  180. {
  181. $oCurrentOrganization = $oOrg;
  182. $sSelected = " selected";
  183. }
  184. else
  185. {
  186. $sSelected = "";
  187. }
  188. $sHtml .= '<option value="'.$oOrg->GetKey().'"'.$sSelected.'>'.$oOrg->Get('name').'</option>';
  189. }
  190. $sHtml .= '</select>';
  191. // Add other dimensions/context information to this form
  192. $oAppContext = new ApplicationContext();
  193. $oAppContext->Reset('org_id'); // Org id is handled above and we want to be able to change it here !
  194. $sHtml .= $oAppContext->GetForForm();
  195. $sHtml .= '</form>';
  196. $sHtml .= '</div>';
  197. return $sHtml;
  198. }
  199. public function DisplayMenu()
  200. {
  201. $oContext = new UserContext();
  202. // Display the menu
  203. $oAppContext = new ApplicationContext();
  204. $iActiveNodeId = utils::ReadParam('menu', '');
  205. $iAccordionIndex = 0;
  206. // 1) Application defined menus
  207. $oSearchFilter = $oContext->NewFilter("menuNode");
  208. $oSearchFilter->AddCondition('parent_id', 0, '=');
  209. $oSearchFilter->AddCondition('type', 'application', '=');
  210. // There may be more criteria added later to have a specific menu based on the user's profile
  211. $oSet = new CMDBObjectSet($oSearchFilter, array('rank' => true));
  212. while ($oRootMenuNode = $oSet->Fetch())
  213. {
  214. $bResult = $oRootMenuNode->DisplayMenu($this, 'application', $oAppContext->GetAsHash(), true, $iActiveNodeId);
  215. if ($bResult)
  216. {
  217. $this->add_ready_script("$('#accordion').accordion('activate', $iAccordionIndex)");
  218. }
  219. $iAccordionIndex++;
  220. }
  221. // 2) User defined menus (Bookmarks)
  222. $oSearchFilter = $oContext->NewFilter("menuNode");
  223. $oSearchFilter->AddCondition('parent_id', 0, '=');
  224. $oSearchFilter->AddCondition('type', 'user', '=');
  225. $oSearchFilter->AddCondition('user_id', UserRights::GetUserId(), '=');
  226. // There may be more criteria added later to have a specific menu based on the user's profile
  227. $oSet = new CMDBObjectSet($oSearchFilter, array('rank' => true));
  228. while ($oRootMenuNode = $oSet->Fetch())
  229. {
  230. $oRootMenuNode->DisplayMenu($this, 'user', $oAppContext->GetAsHash(), true, $iActiveNodeId);
  231. if ($bResult)
  232. {
  233. $this->add_ready_script("$('#accordion').accordion('activate', $iAccordionIndex)");
  234. }
  235. $iAccordionIndex++;
  236. }
  237. // 3) Administrator menu
  238. if (userRights::IsAdministrator())
  239. {
  240. $oSearchFilter = $oContext->NewFilter("menuNode");
  241. $oSearchFilter->AddCondition('parent_id', 0, '=');
  242. $oSearchFilter->AddCondition('type', 'administrator', '=');
  243. // There may be more criteria added later to have a specific menu based on the user's profile
  244. $oSet = new CMDBObjectSet($oSearchFilter, array('rank' => true));
  245. while ($oRootMenuNode = $oSet->Fetch())
  246. {
  247. $oRootMenuNode->DisplayMenu($this, 'administrator', $oAppContext->GetAsHash(), true, $iActiveNodeId);
  248. if ($bResult)
  249. {
  250. $this->add_ready_script("$('#accordion').accordion('activate', $iAccordionIndex)");
  251. }
  252. $iAccordionIndex++;
  253. }
  254. }
  255. $this->AddToMenu("</ul>\n");
  256. }
  257. /**
  258. * Outputs (via some echo) the complete HTML page by assembling all its elements
  259. */
  260. public function output()
  261. {
  262. foreach($this->a_headers as $s_header)
  263. {
  264. header($s_header);
  265. }
  266. $s_captured_output = ob_get_contents();
  267. ob_end_clean();
  268. echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
  269. echo "<html>\n";
  270. echo "<head>\n";
  271. echo "<title>{$this->s_title}</title>\n";
  272. echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
  273. echo $this->get_base_tag();
  274. // Stylesheets MUST be loaded before any scripts otherwise
  275. // jQuery scripts may face some spurious problems (like failing on a 'reload')
  276. foreach($this->a_linked_stylesheets as $a_stylesheet)
  277. {
  278. if ($a_stylesheet['condition'] != "")
  279. {
  280. echo "<!--[if {$a_stylesheet['condition']}]>\n";
  281. }
  282. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$a_stylesheet['link']}\" />\n";
  283. if ($a_stylesheet['condition'] != "")
  284. {
  285. echo "<![endif]-->\n";
  286. }
  287. }
  288. foreach($this->a_linked_scripts as $s_script)
  289. {
  290. echo "<script type=\"text/javascript\" src=\"$s_script\"></script>\n";
  291. }
  292. if (count($this->m_aReadyScripts)>0)
  293. {
  294. $this->add_script("\$(document).ready(function() {\n".implode("\n", $this->m_aReadyScripts)."\n});");
  295. }
  296. if (count($this->a_scripts)>0)
  297. {
  298. echo "<script type=\"text/javascript\">\n";
  299. foreach($this->a_scripts as $s_script)
  300. {
  301. echo "$s_script\n";
  302. }
  303. echo "</script>\n";
  304. }
  305. if (count($this->a_styles)>0)
  306. {
  307. echo "<style>\n";
  308. foreach($this->a_styles as $s_style)
  309. {
  310. echo "$s_style\n";
  311. }
  312. echo "</style>\n";
  313. }
  314. echo "<link rel=\"search\" type=\"application/opensearchdescription+xml\" title=\"iTop\" href=\"./opensearch.xml.php\" />\n";
  315. echo "</head>\n";
  316. echo "<body>\n";
  317. // Render the revision number
  318. if (ITOP_REVISION == '$WCREV$')
  319. {
  320. // This is NOT a version built using the buil system, just display the main version
  321. $sVersionString = "iTop Version ".ITOP_VERSION;
  322. }
  323. else
  324. {
  325. // This is a build made from SVN, let display the full information
  326. $sVersionString = "iTop Version ".ITOP_VERSION." revision ".ITOP_REVISION.", built on: ".ITOP_BUILD_DATE;
  327. }
  328. // Render the text of the global search form
  329. $sText = Utils::ReadParam('text', '');
  330. $sOnClick = "";
  331. if (empty($sText))
  332. {
  333. // if no search text is supplied then
  334. // 1) the search text is filled with "your search"
  335. // 2) clicking on it will erase it
  336. $sText = Dict::S("UI:YourSearch");
  337. $sOnClick = " onclick=\"this.value='';this.onclick=null;\"";
  338. }
  339. $sForm = $this->GetSiloSelectionForm();
  340. // Render the tabs in the page (if any)
  341. foreach($this->m_aTabs as $sTabContainerName => $m_aTabs)
  342. {
  343. $sTabs = '';
  344. $container_index = 0;
  345. if (count($m_aTabs) > 0)
  346. {
  347. $sTabs = "<!-- tabs -->\n<div id=\"tabbedContent_{$container_index}\" class=\"light\">\n";
  348. $sTabs .= "<ul>\n";
  349. // Display the unordered list that will be rendered as the tabs
  350. $i = 0;
  351. foreach($m_aTabs as $sTabName => $sTabContent)
  352. {
  353. $sTabs .= "<li><a href=\"#fragment_$i\" class=\"tab\"><span>".htmlentities($sTabName, ENT_QUOTES, 'UTF-8')."</span></a></li>\n";
  354. $i++;
  355. }
  356. $sTabs .= "</ul>\n";
  357. // Now add the content of the tabs themselves
  358. $i = 0;
  359. foreach($m_aTabs as $sTabName => $sTabContent)
  360. {
  361. $sTabs .= "<div id=\"fragment_$i\">".$sTabContent."</div>\n";
  362. $i++;
  363. }
  364. $sTabs .= "</div>\n<!-- end of tabs-->\n";
  365. }
  366. $this->s_content = str_replace("\$Tabs:$sTabContainerName\$", $sTabs, $this->s_content);
  367. $container_index++;
  368. }
  369. $sUserName = UserRights::GetUser();
  370. $sIsAdmin = UserRights::IsAdministrator() ? '(Administrator)' : '';
  371. if (UserRights::IsAdministrator())
  372. {
  373. $sLogonMessage = Dict::Format('UI:LoggedAsMessage+Admin', $sUserName);
  374. }
  375. else
  376. {
  377. $sLogonMessage = Dict::Format('UI:LoggedAsMessage', $sUserName);
  378. }
  379. $sLogOffMenu = "<span id=\"logOffBtn\"><ul><li><img src=\"../images/onOffBtn.png\"><ul>";
  380. $sLogOffMenu .= "<li><span>$sLogonMessage</span></li>\n";
  381. $sLogOffMenu .= "<li><a href=\"#\">Log Off</a></li>\n";
  382. $sLogOffMenu .= "<li><a href=\"#\">Change password...</a></li>\n";
  383. $sLogOffMenu .= "</ul>\n</li>\n</ul></span>\n";
  384. //$sLogOffMenu = "<span id=\"logOffBtn\" style=\"height:55px;padding:0;margin:0;\"><img src=\"../images/onOffBtn.png\"></span>";
  385. echo '<div id="left-pane" class="ui-layout-west">';
  386. echo '<!-- Beginning of the left pane -->';
  387. echo ' <div id="header-logo">';
  388. echo ' <div id="top-left"></div><div id="logo"><img src="../images/itop-logo.png" style="margin-top:16px; margin-right:40px;"/></div>';
  389. echo ' </div>';
  390. echo ' <div class="header-menu">';
  391. echo ' <div class="icon ui-state-default ui-corner-all"><span id="tPinMenu" class="ui-icon ui-icon-pin-w">pin</span></div>';
  392. echo ' <div style="width:100%; text-align:center;">'.$sForm.'</div>';
  393. echo ' </div>';
  394. echo ' <div id="menu" class="ui-layout-content">';
  395. echo ' <div id="inner_menu">';
  396. echo ' <div id="accordion">';
  397. echo $this->m_sMenu;
  398. echo ' <!-- Beginning of the accordion menu -->';
  399. echo ' <!-- End of the accordion menu-->';
  400. echo ' </div>';
  401. echo ' </div> <!-- /inner menu -->';
  402. echo ' </div> <!-- /menu -->';
  403. echo ' <div class="footer"><span>iTop by Combodo</span></div>';
  404. echo '<!-- End of the left pane -->';
  405. echo '</div>';
  406. echo '<div class="ui-layout-center">';
  407. echo ' <div id="top-bar" style="width:100%">';
  408. echo ' <div id="global-search"><form><table><tr><td id="g-search-input"><input type="text" name="text" value="'.$sText.'"'.$sOnClick.'/></td>';
  409. echo '<td><input type="image" src="../images/searchBtn.png"/></td>';
  410. 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>';
  411. //echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="hidden" name="operation" value="full_text"/></td></tr></table></form></div>';
  412. echo ' </div>';
  413. echo ' <div class="ui-layout-content">';
  414. echo ' <!-- Beginning of page content -->';
  415. echo $this->s_content;
  416. echo ' <!-- End of page content -->';
  417. echo ' </div>';
  418. echo '</div>';
  419. /*
  420. echo "<div class=\"iTopLogo\" title=\"$sVersionString\"><span>iTop</span></div>\n";
  421. //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";
  422. $sText = Utils::ReadParam('text', '');
  423. $sOnClick = "";
  424. if (empty($sText))
  425. {
  426. // if no search text is supplied then
  427. // 1) the search text is filled with "your search"
  428. // 2) clicking on it will erase it
  429. $sText = Dict::S("UI:YourSearch");
  430. $sOnClick = " onclick=\"this.value='';this.onclick=null;\"";
  431. }
  432. $sUserName = UserRights::GetUser();
  433. $sIsAdmin = UserRights::IsAdministrator() ? '(Administrator)' : '';
  434. if (UserRights::IsAdministrator())
  435. {
  436. $sLogonMessage = Dict::Format('UI:LoggedAsMessage+Admin', $sUserName);
  437. }
  438. else
  439. {
  440. $sLogonMessage = Dict::Format('UI:LoggedAsMessage', $sUserName);
  441. }
  442. $sLogOffBtn = Dict::S('UI:Button:Logoff');
  443. $sSearchBtn = Dict::S('UI:Button:GlobalSearch');
  444. echo "<div id=\"Login\" style=\"position:absolute; top:18px; right:16px; width:600px;\">{$sLogonMessage}&nbsp;&nbsp;";
  445. echo "<form action=\"../pages/UI.php\" method=\"post\" style=\"display:inline\">\n";
  446. echo "<input type=\"submit\" value=\"$sLogOffBtn\" />\n";
  447. echo "<input type=\"hidden\" name=\"loginop\" value=\"logoff\" />\n";
  448. echo "</form>\n";
  449. 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\" />
  450. <input type=\"hidden\" name=\"operation\" value=\"full_text\" /></form>\n";
  451. echo "</div>\n";
  452. echo "</div>\n";
  453. // Display the menu
  454. echo "<div id=\"MySplitter\">\n";
  455. echo " <div id=\"LeftPane\">\n";
  456. echo $this->m_sMenu;
  457. echo " </div> <!-- LeftPane -->\n";
  458. echo "<div id=\"RightPane\">\n";
  459. // Display the page's content
  460. echo $this->s_content;
  461. */
  462. // Add the captured output
  463. if (trim($s_captured_output) != "")
  464. {
  465. echo "<div id=\"rawOutput\" title=\"Debug Output\"><div style=\"height:500px; overflow-y:auto;\">$s_captured_output</div></div>\n";
  466. }
  467. echo $this->s_deferred_content;
  468. echo "<div style=\"display:none\" title=\"ex2\" id=\"ex2\">Please wait...</div>\n"; // jqModal Window
  469. echo "<div style=\"display:none\" title=\"dialog\" id=\"ModalDlg\"></div>";
  470. echo "</body>\n";
  471. echo "</html>\n";
  472. }
  473. public function AddTabContainer($sTabContainer)
  474. {
  475. $this->m_aTabs[$sTabContainer] = array();
  476. $this->add("\$Tabs:$sTabContainer\$");
  477. }
  478. public function AddToTab($sTabContainer, $sTabLabel, $sHtml)
  479. {
  480. if (!isset($this->m_aTabs[$sTabContainer][$sTabLabel]))
  481. {
  482. // Set the content of the tab
  483. $this->m_aTabs[$sTabContainer][$sTabLabel] = $sHtml;
  484. }
  485. else
  486. {
  487. // Append to the content of the tab
  488. $this->m_aTabs[$sTabContainer][$sTabLabel] .= $sHtml;
  489. }
  490. }
  491. public function SetCurrentTabContainer($sTabContainer = '')
  492. {
  493. $sPreviousTabContainer = $this->m_sCurrentTabContainer;
  494. $this->m_sCurrentTabContainer = $sTabContainer;
  495. return $sPreviousTabContainer;
  496. }
  497. public function SetCurrentTab($sTabLabel = '')
  498. {
  499. $sPreviousTab = $this->m_sCurrentTab;
  500. $this->m_sCurrentTab = $sTabLabel;
  501. return $sPreviousTab;
  502. }
  503. /**
  504. * Make the given tab the active one, as if it were clicked
  505. * DOES NOT WORK: apparently in the *old* version of jquery
  506. * that we are using this is not supported... TO DO upgrade
  507. * the whole jquery bundle...
  508. */
  509. public function SelectTab($sTabContainer, $sTabLabel)
  510. {
  511. $container_index = 0;
  512. $tab_index = 0;
  513. foreach($this->m_aTabs as $sCurrentTabContainerName => $aTabs)
  514. {
  515. if ($sTabContainer == $sCurrentTabContainerName)
  516. {
  517. foreach($aTabs as $sCurrentTabLabel => $void)
  518. {
  519. if ($sCurrentTabLabel == $sTabLabel)
  520. {
  521. break;
  522. }
  523. $tab_index++;
  524. }
  525. break;
  526. }
  527. $container_index++;
  528. }
  529. $sSelector = '#tabbedContent_'.$container_index.' > ul';
  530. $this->add_ready_script("$('$sSelector').tabs('select', $tab_index);");
  531. }
  532. public function StartCollapsibleSection($sSectionLabel, $bOpen = false)
  533. {
  534. $this->add($this->GetStartCollapsibleSection($sSectionLabel, $bOpen));
  535. }
  536. public function GetStartCollapsibleSection($sSectionLabel, $bOpen = false)
  537. {
  538. $sHtml = '';
  539. static $iSectionId = 0;
  540. $sImgStyle = $bOpen ? ' open' : '';
  541. $sHtml .= "<a id=\"LnkCollapse_$iSectionId\" class=\"CollapsibleLabel{$sImgStyle}\" href=\"#\">$sSectionLabel</a></br>\n";
  542. $sStyle = $bOpen ? '' : 'style="display:none" ';
  543. $sHtml .= "<div id=\"Collapse_$iSectionId\" $sStyle>";
  544. $this->add_ready_script("\$(\"#LnkCollapse_$iSectionId\").click(function() {\$(\"#Collapse_$iSectionId\").slideToggle('normal'); $(\"#LnkCollapse_$iSectionId\").toggleClass('open');});");
  545. //$this->add_ready_script("$('#LnkCollapse_$iSectionId').hide();");
  546. $iSectionId++;
  547. return $sHtml;
  548. }
  549. public function EndCollapsibleSection()
  550. {
  551. $this->add($this->GetEndCollapsibleSection());
  552. }
  553. public function GetEndCollapsibleSection()
  554. {
  555. return "</div>";
  556. }
  557. public function add($sHtml)
  558. {
  559. if (!empty($this->m_sCurrentTabContainer) && !empty($this->m_sCurrentTab))
  560. {
  561. $this->AddToTab($this->m_sCurrentTabContainer, $this->m_sCurrentTab, $sHtml);
  562. }
  563. else
  564. {
  565. parent::add($sHtml);
  566. }
  567. }
  568. /*
  569. public function AddSearchForm($sClassName, $bOpen = false)
  570. {
  571. $iSearchSectionId = 0;
  572. $sStyle = $bOpen ? 'SearchDrawer' : 'SearchDrawer DrawerClosed';
  573. $this->add("<div id=\"Search_$iSearchSectionId\" class=\"$sStyle\">\n");
  574. $this->add("<h1>Search form for ".Metamodel::GetName($sClassName)."</h1>\n");
  575. $this->add_ready_script("\$(\"#LnkSearch_$iSearchSectionId\").click(function() {\$(\"#Search_$iSearchSectionId\").slideToggle('normal'); $(\"#LnkSearch_$iSearchSectionId\").toggleClass('open');});");
  576. $oFilter = new DBObjectSearch($sClassName);
  577. $sFilter = $oFilter->serialize();
  578. $oSet = new CMDBObjectSet($oFilter);
  579. cmdbAbstractObject::DisplaySearchForm($this, $oSet, array('operation' => 'search', 'filter' => $sFilter, 'search_form' => true));
  580. $this->add("</div>\n");
  581. $this->add("<div class=\"HRDrawer\"/></div>\n");
  582. $this->add("<div id=\"LnkSearch_$iSearchSectionId\" class=\"DrawerHandle\">Search</div>\n");
  583. $iSearchSectionId++;
  584. }
  585. */
  586. }
  587. ?>