ajaxwebpage.class.inc.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. require_once("../application/webpage.class.inc.php");
  3. /**
  4. * Simple web page with no includes, header or fancy formatting, useful to
  5. * generate HTML fragments when called by an AJAX method
  6. *
  7. * @package iTopApplication
  8. * @access public
  9. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  10. * @author Denis Flaven <dflaven@free.fr>
  11. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  12. */
  13. class ajax_page extends web_page
  14. {
  15. /**
  16. * Jquery style ready script
  17. * @var Hash
  18. */
  19. protected $m_sReadyScript;
  20. /**
  21. * constructor for the web page
  22. * @param string $s_title Not used
  23. */
  24. function __construct($s_title)
  25. {
  26. parent::__construct($s_title);
  27. $this->m_sReadyScript = "";
  28. }
  29. /**
  30. * Echoes the content of the whole page
  31. * @return void
  32. */
  33. public function output()
  34. {
  35. foreach($this->a_headers as $s_header)
  36. {
  37. header($s_header);
  38. }
  39. $s_captured_output = ob_get_contents();
  40. ob_end_clean();
  41. echo trim($this->s_content);
  42. if (!empty($this->m_sReadyScript))
  43. {
  44. echo "<script>\n";
  45. echo $this->m_sReadyScript; // Ready Scripts are output as simple scripts
  46. echo "</script>\n";
  47. }
  48. if (trim($s_captured_output) != "")
  49. {
  50. echo $s_captured_output;
  51. }
  52. }
  53. /**
  54. * Adds a paragraph with a smaller font into the page
  55. * NOT implemented (i.e does nothing)
  56. * @param string $sText Content of the (small) paragraph
  57. * @return void
  58. */
  59. public function small_p($sText)
  60. {
  61. }
  62. /**
  63. * Adds a tabular content to the web page
  64. * @param Hash $aConfig Configuration of the table: hash array of 'column_id' => 'Column Label'
  65. * @param Hash $aData Hash array. Data to display in the table: each row is made of 'column_id' => Data. A column 'pkey' is expected for each row
  66. * @param Hash $aParams Hash array. Extra parameters for the table. Entry 'class' holds the class of the objects listed in the table
  67. * @return void
  68. */
  69. public function table($aConfig, $aData, $aParams = array())
  70. {
  71. // WARNING WARNING WARNING
  72. // This whole function is actually a copy paste from iTopWebPage::table
  73. $oAppContext = new ApplicationContext();
  74. static $iNbTables = 0;
  75. $iNbTables++;
  76. $sHtml = "";
  77. $sHtml .= "<table class=\"listResults\">\n";
  78. $sHtml .= "<thead>\n";
  79. $sHtml .= "<tr>\n";
  80. foreach($aConfig as $sName=>$aDef)
  81. {
  82. $sHtml .= "<th title=\"".$aDef['description']."\">".$aDef['label']."</th>\n";
  83. }
  84. $sHtml .= "</tr>\n";
  85. $sHtml .= "</thead>\n";
  86. $sHtml .= "<tbody>\n";
  87. foreach($aData as $aRow)
  88. {
  89. if (false) //(isset($aParams['preview']) && $aParams['preview'])
  90. {
  91. $sHtml .= "<tr id=\"Row_".$iNbTables."_".$aRow['key']."\" onClick=\"DisplayPreview(".$iNbTables.",".$aRow['key'].",'".$aParams['class']."')\">\n";
  92. }
  93. else if (isset($aRow['key']))
  94. {
  95. $sHtml .= "<tr onDblClick=\"DisplayDetails(".$aRow['key'].",'".$aParams['class']."')\">\n";
  96. }
  97. else
  98. {
  99. $sHtml .= "<tr>\n";
  100. }
  101. foreach($aConfig as $sName=>$aVoid)
  102. {
  103. if ($sName != 'key')
  104. {
  105. $sValue = empty($aRow[$sName]) ? '&nbsp;' : $aRow[$sName];
  106. $sHtml .= "<td>$sValue</td>\n";
  107. }
  108. else
  109. {
  110. $sUIPage = cmdbAbstractObject::ComputeUIPage($aParams['class']);
  111. $sHtml .= "<td><a class=\"no-arrow\" href=\"$sUIPage?operation=details&id=".$aRow['key']."&class=".$aParams['class']."&".$oAppContext->GetForLink()."\"><img src=\"../images/zoom.gif\" title=\"Details\" border=\"0\"></a></td>\n";
  112. }
  113. }
  114. $sHtml .= "</tr>\n";
  115. }
  116. $sHtml .= "</tbody>\n";
  117. $sHtml .= "</table>\n";
  118. if (isset($aParams['preview']) && $aParams['preview'])
  119. {
  120. $sHtml .= "<div class=\"PreviewPane\" id=\"PreviewPane_".$iNbTables."\" style=\"height:100px;border:1px solid black;margin-top:2px;padding:3px;text-align:left;display:none;\">Preview Pane</div>";
  121. }
  122. $this->add($sHtml);
  123. }
  124. /**
  125. * Adds a script to be executed when the DOM is ready (typical JQuery use)
  126. * NOT implemented in this version of the class.
  127. * @return void
  128. */
  129. public function add_ready_script($sScript)
  130. {
  131. // Does nothing in ajax rendered content.. for now...
  132. // Maybe we should add this as a simple <script> tag at the end of the output
  133. // considering that at this time everything in the page is "ready"...
  134. $this->m_sReadyScript .= $sScript;
  135. }
  136. }
  137. ?>