itopwebpage.class.inc.php 17 KB

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