itopwebpage.class.inc.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <?php
  2. require_once("../application/nicewebpage.class.inc.php");
  3. require_once("../application/usercontext.class.inc.php");
  4. require_once("../application/applicationcontext.class.inc.php");
  5. /**
  6. * Web page with some associated CSS and scripts (jquery) for a fancier display
  7. */
  8. class iTopWebPage extends NiceWebPage
  9. {
  10. private $m_sMenu;
  11. private $m_currentOrganization;
  12. private $m_aTabs;
  13. private $m_sCurrentTabContainer;
  14. private $m_sCurrentTab;
  15. public function __construct($sTitle, $currentOrganization)
  16. {
  17. parent::__construct($sTitle);
  18. $this->m_sCurrentTabContainer = '';
  19. $this->m_sCurrentTab = '';
  20. $this->m_aTabs = array();
  21. $this->m_sMenu = "";
  22. $oAppContext = new ApplicationContext();
  23. $sExtraParams = $oAppContext->GetForLink();
  24. $this->add_header("Content-type: text/html; charset=utf-8");
  25. $this->add_header("Cache-control: no-cache");
  26. $this->m_currentOrganization = $currentOrganization;
  27. $this->add_linked_script("../js/jquery.dimensions.js");
  28. $this->add_linked_script("../js/splitter.js");
  29. $this->add_linked_script("../js/jquery.tablehover.js");
  30. $this->add_linked_script("../js/jquery.treeview.js");
  31. $this->add_linked_script("../js/jquery.autocomplete.js");
  32. $this->add_linked_script("../js/jquery.bgiframe.js");
  33. $this->add_linked_script("../js/jquery.jdMenu.js");
  34. $this->add_linked_script("../js/date.js");
  35. $this->add_linked_script("../js/jquery.date.picker.js");
  36. $this->add_linked_script("../js/jquery.tablesorter.min.js");
  37. $this->add_linked_script("../js/utils.js");
  38. //$this->add_linked_script("../js/jquery-ui-personalized-1.5.3.js");
  39. $this->add_linked_script("../js/swfobject.js");
  40. $this->add_linked_stylesheet("../css/jquery.treeview.css");
  41. $this->add_linked_stylesheet("../css/jquery.autocomplete.css");
  42. $this->add_linked_stylesheet("../css/date.picker.css");
  43. $this->add_ready_script(
  44. <<<EOF
  45. // Vertical splitter. The min/max/starting sizes for the left (A) pane
  46. // are set here. All values are in pixels.
  47. $("#MySplitter").splitter({
  48. type: "v",
  49. minA: 100, initA: 250, maxA: 500,
  50. accessKey: "|"
  51. });
  52. // Horizontal splitter, nested in the right pane of the vertical splitter.
  53. if ( $("#TopPane").length > 0)
  54. {
  55. $("#RightPane").splitter({
  56. type: "h" //,
  57. //minA: 100, initA: 150, maxA: 500,
  58. //accessKey: "_"
  59. });
  60. }
  61. // Manually set the outer splitter's height to fill the browser window.
  62. // This must be re-done any time the browser window is resized.
  63. $(window).bind("resize", function(){
  64. var ms = $("#MySplitter");
  65. var top = ms.offset().top; // from dimensions.js
  66. var wh = $(window).height();
  67. // Account for margin or border on the splitter container
  68. var mrg = parseInt(ms.css("marginBottom")) || 0;
  69. var brd = parseInt(ms.css("borderBottomWidth")) || 0;
  70. ms.css("height", (wh-top-mrg-brd)+"px");
  71. // IE fires resize for splitter; others don't so do it here
  72. if ( !jQuery.browser.msie )
  73. ms.trigger("resize");
  74. }).trigger("resize");
  75. var ms = $("#MySplitter");
  76. ms.trigger("resize");
  77. if ( $("#TopPane").length > 0)
  78. {
  79. $("#RightPane").trigger("resize");
  80. }
  81. $("#tabbedContent > ul").tabs( 1, { fxFade: true, fxSpeed: 'fast' } ); // tabs
  82. $("table.listResults").tableHover(); // hover tables
  83. $(".listResults").tablesorter( { headers: { 0:{sorter: false }}, widgets: ['zebra']} ); // sortable and zebra tables
  84. $(".date-pick").datePicker( {clickInput: false, createButton: true, startDate: '2000-01-01'} ); // Date picker
  85. $('#ModalDlg').jqm({ajax: '@href', trigger: 'a.jqmTrigger', overlay:70, modal:true, toTop:true}); // jqModal Window
  86. //$('.display_block').draggable(); // make the blocks draggable
  87. EOF
  88. );
  89. $this->add_script("
  90. // For automplete
  91. function findValue(li) {
  92. if( li == null ) return alert(\"No match!\");
  93. // if coming from an AJAX call, let's use the CityId as the value
  94. if( !!li.extra ) var sValue = li.extra[0];
  95. // otherwise, let's just display the value in the text box
  96. else var sValue = li.selectValue;
  97. //alert(\"The value you selected was: \" + sValue);
  98. }
  99. function selectItem(li) {
  100. findValue(li);
  101. }
  102. function formatItem(row) {
  103. return row[0];
  104. }
  105. function goBack()
  106. {
  107. window.history.back();
  108. }
  109. ");
  110. $this->DisplayMenu();
  111. }
  112. public function AddToMenu($sHtml)
  113. {
  114. $this->m_sMenu .= $sHtml;
  115. }
  116. public function DisplayMenu()
  117. {
  118. // Combo box to select the organization
  119. $this->AddToMenu("<div id=\"OrganizationSelection\">
  120. <form style=\"display:inline\" action=\"./UI.php\"><select style=\"width:150px;font-size:x-small\" name=\"org_id\" title=\"Pick an organization\" onChange=\"this.form.submit();\">\n");
  121. // List of visible Organizations
  122. $oContext = new UserContext();
  123. $oSearchFilter = $oContext->NewFilter("bizOrganization");
  124. $oSet = new CMDBObjectSet($oSearchFilter);
  125. $sSelected = ($this->m_currentOrganization == '') ? ' selected' : '';
  126. $this->AddToMenu("<option value=\"\"$sSelected> All Organizations </option>");
  127. if ($oSet->Count() > 0)
  128. while($oOrg = $oSet->Fetch())
  129. {
  130. if ($this->m_currentOrganization == $oOrg->GetKey())
  131. {
  132. $oCurrentOrganization = $oOrg;
  133. $sSelected = " selected";
  134. }
  135. else
  136. {
  137. $sSelected = "";
  138. }
  139. $this->AddToMenu("<option value=\"".$oOrg->GetKey()."\"$sSelected>".$oOrg->Get('name')."</option>\n");
  140. }
  141. $this->AddToMenu("</select>\n");
  142. // Add other dimensions/context information to this form
  143. $oAppContext = new ApplicationContext();
  144. $oAppContext->Reset('org_id'); // Org id is handled above and we want to be able to change it here !
  145. $this->AddToMenu($oAppContext->GetForForm());
  146. $this->AddToMenu("</form>\n");
  147. $this->AddToMenu("</div>\n");
  148. $this->AddToMenu("<ul id=\"browser\" class=\"dir\">\n");
  149. // Display the menu
  150. $oAppContext = new ApplicationContext();
  151. // 1) Application defined menus
  152. $oSearchFilter = $oContext->NewFilter("menuNode");
  153. $oSearchFilter->AddCondition('parent_id', 0, '=');
  154. $oSearchFilter->AddCondition('type', 'application', '=');
  155. // There may be more criteria added later to have a specific menu based on the user's profile
  156. $oSet = new CMDBObjectSet($oSearchFilter, array('rank' => true));
  157. while ($oRootMenuNode = $oSet->Fetch())
  158. {
  159. $oRootMenuNode->DisplayMenu($this, 'application', $oAppContext->GetAsHash());
  160. }
  161. // 2) User defined menus (Bookmarks)
  162. $oSearchFilter = $oContext->NewFilter("menuNode");
  163. $oSearchFilter->AddCondition('parent_id', 0, '=');
  164. $oSearchFilter->AddCondition('type', 'user', '=');
  165. $oSearchFilter->AddCondition('user_id', UserRights::GetUserId(), '=');
  166. // There may be more criteria added later to have a specific menu based on the user's profile
  167. $oSet = new CMDBObjectSet($oSearchFilter, array('rank' => true));
  168. while ($oRootMenuNode = $oSet->Fetch())
  169. {
  170. $oRootMenuNode->DisplayMenu($this, 'user', $oAppContext->GetAsHash());
  171. }
  172. // 3) Administrator menu
  173. if (userRights::IsAdministrator())
  174. {
  175. $oSearchFilter = $oContext->NewFilter("menuNode");
  176. $oSearchFilter->AddCondition('parent_id', 0, '=');
  177. $oSearchFilter->AddCondition('type', 'administrator', '=');
  178. // There may be more criteria added later to have a specific menu based on the user's profile
  179. $oSet = new CMDBObjectSet($oSearchFilter, array('rank' => true));
  180. while ($oRootMenuNode = $oSet->Fetch())
  181. {
  182. $oRootMenuNode->DisplayMenu($this, 'administrator', $oAppContext->GetAsHash());
  183. }
  184. }
  185. $this->AddToMenu("</ul>\n");
  186. }
  187. /**
  188. * Outputs (via some echo) the complete HTML page by assembling all its elements
  189. */
  190. public function output()
  191. {
  192. foreach($this->a_headers as $s_header)
  193. {
  194. header($s_header);
  195. }
  196. $s_captured_output = ob_get_contents();
  197. ob_end_clean();
  198. echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
  199. echo "<html>\n";
  200. echo "<head>\n";
  201. echo "<title>{$this->s_title}</title>\n";
  202. echo $this->get_base_tag();
  203. // Stylesheets MUST be loaded before any scripts otherwise
  204. // jQuery scripts may face some spurious problems (like failing on a 'reload')
  205. foreach($this->a_linked_stylesheets as $a_stylesheet)
  206. {
  207. if ($a_stylesheet['condition'] != "")
  208. {
  209. echo "<!--[if {$a_stylesheet['condition']}]>\n";
  210. }
  211. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$a_stylesheet['link']}\" />\n";
  212. if ($a_stylesheet['condition'] != "")
  213. {
  214. echo "<![endif]-->\n";
  215. }
  216. }
  217. foreach($this->a_linked_scripts as $s_script)
  218. {
  219. echo "<script type=\"text/javascript\" src=\"$s_script\"></script>\n";
  220. }
  221. if (count($this->m_aReadyScripts)>0)
  222. {
  223. $this->add_script("\$(document).ready(function() {\n".implode("\n", $this->m_aReadyScripts)."\n});");
  224. }
  225. if (count($this->a_scripts)>0)
  226. {
  227. echo "<script type=\"text/javascript\">\n";
  228. foreach($this->a_scripts as $s_script)
  229. {
  230. echo "$s_script\n";
  231. }
  232. echo "</script>\n";
  233. }
  234. if (count($this->a_styles)>0)
  235. {
  236. echo "<style>\n";
  237. foreach($this->a_styles as $s_style)
  238. {
  239. echo "$s_style\n";
  240. }
  241. echo "</style>\n";
  242. }
  243. echo "<link rel=\"search\" type=\"application/opensearchdescription+xml\" title=\"iTop\" href=\"./opensearch.xml.php\" />\n";
  244. echo "</head>\n";
  245. echo "<body>\n";
  246. // Display the header
  247. if (ITOP_REVISION == '$WCREV$')
  248. {
  249. // This is NOT a version built using the buil system, just display the main version
  250. $sVersionString = "iTop Version ".ITOP_VERSION;
  251. }
  252. else
  253. {
  254. // This is a build made from SVN, let display the full information
  255. $sVersionString = "iTop Version ".ITOP_VERSION." revision ".ITOP_REVISION.", built on: ".ITOP_BUILD_DATE;
  256. }
  257. echo "<div id=\"Header\">\n";
  258. echo "<div class=\"iTopLogo\" title=\"$sVersionString\"><span>iTop</span></div>\n";
  259. //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";
  260. $sText = Utils::ReadParam('text', '');
  261. $sOnClick = "";
  262. if (empty($sText))
  263. {
  264. // if no search text is supplied then
  265. // 1) the search text is filled with "your search"
  266. // 2) clicking on it will erase it
  267. $sText = "Your search";
  268. $sOnClick = " onclick=\"this.value='';this.onclick=null;\"";
  269. }
  270. $sUserName = UserRights::GetUser();
  271. $sIsAdmin = UserRights::IsAdministrator() ? '(Administrator)' : '';
  272. echo "<div id=\"Login\" style=\"position:absolute; top:18px; right:16px; width:500px;\">Logged in as '$sUserName'&nbsp;$sIsAdmin&nbsp;&nbsp;";
  273. echo "<form action=\"../pages/UI.php\" method=\"post\" style=\"display:inline\">\n";
  274. echo "<input type=\"submit\" value=\"Log off\" />\n";
  275. echo "<input type=\"hidden\" name=\"operation\" value=\"logoff\" />\n";
  276. echo "</form>\n";
  277. 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=\"Search\" />
  278. <input type=\"hidden\" name=\"operation\" value=\"full_text\" /></form>\n";
  279. echo "</div>\n";
  280. echo "</div>\n";
  281. // Display the menu
  282. echo "<div id=\"MySplitter\">\n";
  283. echo " <div id=\"LeftPane\">\n";
  284. echo $this->m_sMenu;
  285. echo " </div> <!-- LeftPane -->\n";
  286. echo "<div id=\"RightPane\">\n";
  287. // Render the tabs in the page (if any)
  288. foreach($this->m_aTabs as $sTabContainerName => $m_aTabs)
  289. {
  290. $sTabs = '';
  291. if (count($m_aTabs) > 0)
  292. {
  293. $sTabs = "<!-- tabs -->\n<div id=\"tabbedContent\" class=\"light\">\n";
  294. $sTabs .= "<ul>\n";
  295. // Display the unordered list that will be rendered as the tabs
  296. $i = 0;
  297. foreach($m_aTabs as $sTabName => $sTabContent)
  298. {
  299. $sTabs .= "<li><a href=\"#fragment_$i\" class=\"tab\"><span>".htmlentities($sTabName)."</span></a></li>\n";
  300. $i++;
  301. }
  302. $sTabs .= "</ul>\n";
  303. // Now add the content of the tabs themselves
  304. $i = 0;
  305. foreach($m_aTabs as $sTabName => $sTabContent)
  306. {
  307. $sTabs .= "<div id=\"fragment_$i\">".$sTabContent."</div>\n";
  308. $i++;
  309. }
  310. $sTabs .= "</div>\n<!-- end of tabs-->\n";
  311. }
  312. $this->s_content = str_replace("\$Tabs:$sTabContainerName\$", $sTabs, $this->s_content);
  313. }
  314. // Display the page's content
  315. echo $this->s_content;
  316. // Add the captured output
  317. if (trim($s_captured_output) != "")
  318. {
  319. echo "<div class=\"raw_output\">$s_captured_output</div>\n";
  320. }
  321. echo $this->s_deferred_content;
  322. echo "<div class=\"jqmWindow\" id=\"ex2\">Please wait...</div>\n"; // jqModal Window
  323. echo "</div> <!-- RightPane -->\n";
  324. echo "</div> <!-- Splitter -->\n";
  325. echo "<div class=\"jqmWindow\" id=\"ModalDlg\"></div>";
  326. echo "</body>\n";
  327. echo "</html>\n";
  328. }
  329. public function AddTabContainer($sTabContainer)
  330. {
  331. $this->m_aTabs[$sTabContainer] = array();
  332. $this->add("\$Tabs:$sTabContainer\$");
  333. }
  334. public function AddToTab($sTabContainer, $sTabLabel, $sHtml)
  335. {
  336. if (!isset($this->m_aTabs[$sTabContainer][$sTabLabel]))
  337. {
  338. // Set the content of the tab
  339. $this->m_aTabs[$sTabContainer][$sTabLabel] = $sHtml;
  340. }
  341. else
  342. {
  343. // Append to the content of the tab
  344. $this->m_aTabs[$sTabContainer][$sTabLabel] .= $sHtml;
  345. }
  346. }
  347. public function SetCurrentTabContainer($sTabContainer = '')
  348. {
  349. $sPreviousTabContainer = $this->m_sCurrentTabContainer;
  350. $this->m_sCurrentTabContainer = $sTabContainer;
  351. return $sPreviousTabContainer;
  352. }
  353. public function SetCurrentTab($sTabLabel = '')
  354. {
  355. $sPreviousTab = $this->m_sCurrentTab;
  356. $this->m_sCurrentTab = $sTabLabel;
  357. return $sPreviousTab;
  358. }
  359. public function StartCollapsibleSection($sSectionLabel, $bOpen = false)
  360. {
  361. $this->add($this->GetStartCollapsibleSection($sSectionLabel, $bOpen));
  362. }
  363. public function GetStartCollapsibleSection($sSectionLabel, $bOpen = false)
  364. {
  365. $sHtml = '';
  366. static $iSectionId = 0;
  367. $sImgStyle = $bOpen ? ' open' : '';
  368. $sHtml .= "<a id=\"LnkCollapse_$iSectionId\" class=\"CollapsibleLabel{$sImgStyle}\" href=\"#\">$sSectionLabel</a></br>\n";
  369. $sStyle = $bOpen ? '' : 'style="display:none" ';
  370. $sHtml .= "<div id=\"Collapse_$iSectionId\" $sStyle>";
  371. $this->add_ready_script("\$(\"#LnkCollapse_$iSectionId\").click(function() {\$(\"#Collapse_$iSectionId\").slideToggle('normal'); $(\"#LnkCollapse_$iSectionId\").toggleClass('open');});");
  372. //$this->add_ready_script("$('#LnkCollapse_$iSectionId').hide();");
  373. $iSectionId++;
  374. return $sHtml;
  375. }
  376. public function EndCollapsibleSection()
  377. {
  378. $this->add($this->GetEndCollapsibleSection());
  379. }
  380. public function GetEndCollapsibleSection()
  381. {
  382. return "</div>";
  383. }
  384. public function add($sHtml)
  385. {
  386. if (!empty($this->m_sCurrentTabContainer) && !empty($this->m_sCurrentTab))
  387. {
  388. $this->AddToTab($this->m_sCurrentTabContainer, $this->m_sCurrentTab, $sHtml);
  389. }
  390. else
  391. {
  392. parent::add($sHtml);
  393. }
  394. }
  395. /*
  396. public function AddSearchForm($sClassName, $bOpen = false)
  397. {
  398. $iSearchSectionId = 0;
  399. $sStyle = $bOpen ? 'SearchDrawer' : 'SearchDrawer DrawerClosed';
  400. $this->add("<div id=\"Search_$iSearchSectionId\" class=\"$sStyle\">\n");
  401. $this->add("<h1>Search form for ".Metamodel::GetName($sClassName)."</h1>\n");
  402. $this->add_ready_script("\$(\"#LnkSearch_$iSearchSectionId\").click(function() {\$(\"#Search_$iSearchSectionId\").slideToggle('normal'); $(\"#LnkSearch_$iSearchSectionId\").toggleClass('open');});");
  403. $oFilter = new DBObjectSearch($sClassName);
  404. $sFilter = $oFilter->serialize();
  405. $oSet = new CMDBObjectSet($oFilter);
  406. cmdbAbstractObject::DisplaySearchForm($this, $oSet, array('operation' => 'search', 'filter' => $sFilter, 'search_form' => true));
  407. $this->add("</div>\n");
  408. $this->add("<div class=\"HRDrawer\"/></div>\n");
  409. $this->add("<div id=\"LnkSearch_$iSearchSectionId\" class=\"DrawerHandle\">Search</div>\n");
  410. $iSearchSectionId++;
  411. }
  412. */
  413. }
  414. ?>