ajaxwebpage.class.inc.php 5.3 KB

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