itopwebpage.class.inc.php 15 KB

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