/library/ViMbAdmin/Smarty/functions/function.ViMbAdmin_Messages.php

https://github.com/basilgohar/ViMbAdmin · PHP · 138 lines · 71 code · 26 blank · 41 comment · 9 complexity · c5ad5198bf72a88df165d1f92d85a77d MD5 · raw file

  1. <?php
  2. /**
  3. * Open Solutions' ViMbAdmin Project.
  4. *
  5. * This file is part of Open Solutions' ViMbAdmin Project which is a
  6. * project which provides an easily manageable web based virtual
  7. * mailbox administration system.
  8. *
  9. * Copyright (c) 2011 Open Source Solutions Limited
  10. *
  11. * ViMbAdmin is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation, either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * ViMbAdmin is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with ViMbAdmin. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. * Open Source Solutions Limited T/A Open Solutions
  25. * 147 Stepaside Park, Stepaside, Dublin 18, Ireland.
  26. * Barry O'Donovan <barry _at_ opensolutions.ie>
  27. *
  28. * @copyright Copyright (c) 2011 Open Source Solutions Limited
  29. * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License, version 3 (GPLv3)
  30. * @author Open Source Solutions Limited <info _at_ opensolutions.ie>
  31. * @author Barry O'Donovan <barry _at_ opensolutions.ie>
  32. * @author Roland Huszti <roland _at_ opensolutions.ie>
  33. */
  34. /*
  35. * Displays system messages from session.
  36. *
  37. * @return string the JavaScript code
  38. *
  39. * @package ViMbAdmin
  40. * @subpackage Smarty_Functions
  41. */
  42. function smarty_function_ViMbAdmin_Messages( $params, &$smarty )
  43. {
  44. $messages = $smarty->getTemplateVars( 'ViMbAdmin_Messages' );
  45. if( $messages === null ) $messages = array();
  46. if( isset( $_SESSION['Application']['ViMbAdmin_Messages'] ) && is_array( $_SESSION['Application']['ViMbAdmin_Messages'] )
  47. && sizeof( $_SESSION['Application']['ViMbAdmin_Messages'] ) > 0 )
  48. {
  49. $messages = array_merge( $messages, $_SESSION['Application']['ViMbAdmin_Messages'] );
  50. unset( $_SESSION['Application']['ViMbAdmin_Messages'] );
  51. }
  52. if ( $messages == array() ) return '';
  53. $message = '<div id="vimbadmin_messages">' . "\n";
  54. $count = 0;
  55. foreach( $messages as $oneMessage )
  56. {
  57. if( isset( $params['randomid'] ) && $params['randomid'] ) $count = mt_rand();
  58. $items = $oneMessage->getMessage();
  59. if( !is_array( $items ) )
  60. $items = array( $items );
  61. foreach( $items as $item )
  62. {
  63. $message .= <<<END_MESSAGE
  64. <div id="vimbadmin-message-{$count}">
  65. <div class="vimbadmin-message vimbadmin-message-{$oneMessage->getClass()}">
  66. <p>
  67. END_MESSAGE;
  68. switch( $oneMessage->getClass() )
  69. {
  70. case ViMbAdmin_Message::ERROR:
  71. $message .= ' <span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-alert"></span>' . "\n";
  72. break;
  73. default:
  74. break;
  75. }
  76. $message .= <<<END_MESSAGE
  77. {$item}
  78. <span id="vimbadmin-message-close-icon-{$count}" class="ui-state-default ui-corner-all vimbadmin-message-icon" title="Close">
  79. <span class="ui-icon ui-icon-close"></span>
  80. </span>
  81. </p>
  82. </div>
  83. </div>
  84. END_MESSAGE;
  85. } // end inner foreach
  86. $count++;
  87. } // end foreach()
  88. // add JavaScript
  89. $message .= <<<END_JS
  90. <script type="text/javascript"> /* <![CDATA[ */
  91. jQuery( document ).ready( function()
  92. {
  93. $("span[id^='vimbadmin-message-close-icon-']").hover( function() {
  94. var theid= $(this).attr('id').substr(29);
  95. $("span[id='vimbadmin-message-close-icon-" + theid + "'] > span").addClass( 'ui-state-hover' );
  96. },
  97. function() {
  98. var theid= $(this).attr('id').substr(29);
  99. $("span[id='vimbadmin-message-close-icon-" + theid + "'] > span").removeClass( 'ui-state-hover' );
  100. }
  101. );
  102. $("span[id^='vimbadmin-message-close-icon-']").click( function() {
  103. var theid= $(this).attr('id').substr(29);
  104. $("div[id='vimbadmin-message-" + theid + "']").slideUp( 'fast', function() {
  105. $("div[id='vimbadmin-message-" + theid + "']").remove()
  106. } );
  107. } );
  108. } );
  109. /* ]]> */ </script>
  110. END_JS;
  111. return $message . "</div>\n";
  112. }