portalwebpage.class.inc.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. * Class PortalWebPage
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. require_once(APPROOT."/application/nicewebpage.class.inc.php");
  25. require_once(APPROOT."/application/applicationcontext.class.inc.php");
  26. require_once(APPROOT."/application/user.preferences.class.inc.php");
  27. /**
  28. * Web page with some associated CSS and scripts (jquery) for a fancier display
  29. * of the Portal web page
  30. */
  31. class PortalWebPage extends NiceWebPage
  32. {
  33. /**
  34. * Portal menu
  35. */
  36. protected $m_aMenuButtons;
  37. public function __construct($sTitle, $sAlternateStyleSheet = '')
  38. {
  39. $this->m_aMenuButtons = array();
  40. parent::__construct($sTitle);
  41. $this->add_header("Content-type: text/html; charset=utf-8");
  42. $this->add_header("Cache-control: no-cache");
  43. $this->add_linked_stylesheet("../css/jquery.treeview.css");
  44. $this->add_linked_stylesheet("../css/jquery.autocomplete.css");
  45. if ($sAlternateStyleSheet != '')
  46. {
  47. $this->add_linked_stylesheet("../portal/$sAlternateStyleSheet/portal.css");
  48. }
  49. else
  50. {
  51. $this->add_linked_stylesheet("../portal/portal.css");
  52. }
  53. $this->add_linked_script('../js/jquery.layout.min.js');
  54. $this->add_linked_script('../js/jquery.ba-bbq.min.js');
  55. $this->add_linked_script("../js/jquery.tablehover.js");
  56. $this->add_linked_script("../js/jquery.treeview.js");
  57. $this->add_linked_script("../js/jquery.autocomplete.js");
  58. $this->add_linked_script("../js/jquery.bgiframe.js");
  59. $this->add_linked_script("../js/jquery.positionBy.js");
  60. $this->add_linked_script("../js/jquery.popupmenu.js");
  61. $this->add_linked_script("../js/date.js");
  62. $this->add_linked_script("../js/jquery.tablesorter.min.js");
  63. $this->add_linked_script("../js/jquery.blockUI.js");
  64. $this->add_linked_script("../js/utils.js");
  65. $this->add_linked_script("../js/forms-json-utils.js");
  66. $this->add_linked_script("../js/swfobject.js");
  67. $this->add_ready_script(
  68. <<<EOF
  69. try
  70. {
  71. //add new widget called TruncatedList to properly display truncated lists when they are sorted
  72. $.tablesorter.addWidget({
  73. // give the widget a id
  74. id: "truncatedList",
  75. // format is called when the on init and when a sorting has finished
  76. format: function(table)
  77. {
  78. // Check if there is a "truncated" line
  79. this.truncatedList = false;
  80. if ($("tr td.truncated",table).length > 0)
  81. {
  82. this.truncatedList = true;
  83. }
  84. if (this.truncatedList)
  85. {
  86. $("tr td",table).removeClass('truncated');
  87. $("tr:last td",table).addClass('truncated');
  88. }
  89. }
  90. });
  91. $.tablesorter.addWidget({
  92. // give the widget a id
  93. id: "myZebra",
  94. // format is called when the on init and when a sorting has finished
  95. format: function(table)
  96. {
  97. // Replace the 'red even' lines by 'red_even' since most browser do not support 2 classes selector in CSS, etc..
  98. $("tbody tr:even",table).addClass('even');
  99. $("tbody tr.red:even",table).removeClass('red').removeClass('even').addClass('red_even');
  100. $("tbody tr.orange:even",table).removeClass('orange').removeClass('even').addClass('orange_even');
  101. $("tbody tr.green:even",table).removeClass('green').removeClass('even').addClass('green_even');
  102. }
  103. });
  104. $("table.listResults").tableHover(); // hover tables
  105. $(".listResults").tablesorter( { widgets: ['myZebra', 'truncatedList']} ); // sortable and zebra tables
  106. $(".date-pick").datepicker({
  107. showOn: 'button',
  108. buttonImage: '../images/calendar.png',
  109. buttonImageOnly: true,
  110. dateFormat: 'yy-mm-dd',
  111. constrainInput: false,
  112. changeMonth: true,
  113. changeYear: true
  114. });
  115. $('.resizable').resizable(); // Make resizable everything that claims to be resizable !
  116. }
  117. catch(err)
  118. {
  119. // Do something with the error !
  120. alert(err);
  121. }
  122. EOF
  123. );
  124. $this->add_script(
  125. <<<EOF
  126. function CheckSelection(sMessage)
  127. {
  128. var bResult = ($('input:checked').length > 0);
  129. if (!bResult)
  130. {
  131. alert(sMessage);
  132. }
  133. return bResult;
  134. }
  135. function GoBack()
  136. {
  137. var form = $('#request_form');
  138. var step = $('input[name=step]');
  139. form.unbind('submit'); // De-activate validation
  140. step.val(step.val() -2); // To go Back one step: next step is x, current step is x-1, previous step is x-2
  141. form.submit(); // Go
  142. }
  143. EOF
  144. );
  145. }
  146. /**
  147. * Add a button to the portal's main menu
  148. */
  149. public function AddMenuButton($sId, $sLabel, $sHyperlink)
  150. {
  151. $this->m_aMenuButtons[] = array('id' => $sId, 'label' => $sLabel, 'hyperlink' => $sHyperlink);
  152. }
  153. public function output()
  154. {
  155. $sMenu = '';
  156. $this->AddMenuButton('logoff', 'Portal:Disconnect', '../pages/logoff.php?portal=1'); // This menu is always present and is the last one
  157. foreach($this->m_aMenuButtons as $aMenuItem)
  158. {
  159. $sMenu .= "<a class=\"button\" id=\"{$aMenuItem['id']}\" href=\"{$aMenuItem['hyperlink']}\"><span>".Dict::S($aMenuItem['label'])."</span></a>";
  160. }
  161. $this->s_content = '<div id="portal"><div id="banner"><div id="logo"></div>'.$sMenu.'</div><div id="content">'.$this->s_content.'</div></div>';
  162. parent::output();
  163. }
  164. }
  165. ?>