Guest User

Untitled

a guest
Jan 14th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @package evaluation topics
  5. * @version $Id: viewtopic.php , v 1.0.8 2008-11-15 Novan $
  6. * @copyright (c) 2008 RenΓ© Espenhahn (svrider.de)
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10.  
  11. if (!defined('IN_PHPBB'))
  12. {
  13. exit;
  14. }
  15.  
  16. function evaluation_display()
  17. {
  18. global $template, $db, $user, $phpbb_root_path, $phpEx, $auth, $topic_data, $start;
  19.  
  20. $user_id = $user->data['user_id'];
  21.  
  22. if(($user_id != ANONYMOUS) && ($auth->acl_get('f_evaluation', $topic_data['forum_id'])))
  23. {
  24. $sql = 'SELECT e2.evaluation, ROUND(AVG(e1.evaluation), 2) AS ergebnis, COUNT(e1.evaluation) AS anzahl
  25. FROM ' . TOPICS_EVALUATION_TABLE . ' e1
  26. LEFT JOIN ' . TOPICS_EVALUATION_TABLE . ' e2
  27. ON ((e2.topic_id = e1.topic_id) AND (e2.user_id = ' . $user_id . '))
  28. WHERE e1.topic_id = ' . $topic_data['topic_id'] . '
  29. GROUP BY e1.topic_id';
  30. }
  31. else
  32. {
  33. $sql = 'SELECT ROUND(AVG(evaluation), 2) AS ergebnis, COUNT(evaluation) AS anzahl FROM ' . TOPICS_EVALUATION_TABLE . ' WHERE topic_id = ' . $topic_data['topic_id'];
  34. }
  35. $evaluation = $db->sql_fetchrow($db->sql_query($sql));
  36. $out = '';
  37. $eval = false;
  38. $mouse = '';
  39.  
  40. if($user_id != ANONYMOUS)
  41. {
  42. $eval_own = $auth->acl_get('f_evaluation_own', $topic_data['forum_id']);
  43. $eval_change = $auth->acl_get('f_evaluation_change', $topic_data['forum_id']);
  44. $eval = $auth->acl_get('f_evaluation', $topic_data['forum_id']);
  45.  
  46. if(($eval) && (($topic_data['topic_poster'] != $user_id) || ($eval_own)) && ((!$evaluation['evaluation']) || ($eval_change)))
  47. {
  48. if($vote = request_var('evaluation', 0))
  49. {
  50. if(($vote > 0) && ($vote <= $topic_data['forum_evaluation'])) // Check if it is an ordanary vote and not cheating
  51. {
  52. $sql = 'SELECT evaluation FROM ' . TOPICS_EVALUATION_TABLE . ' WHERE topic_id = ' . $topic_data['topic_id'] . ' AND user_id = ' . $user->data['user_id'];
  53. $check = $db->sql_fetchrow($db->sql_query($sql));
  54.  
  55. if(is_array($check) && $check['evaluation'] != $vote)
  56. {
  57. $sql = 'UPDATE ' . TOPICS_EVALUATION_TABLE . ' SET
  58. evaluation = "' . $vote . '"
  59. WHERE topic_id = ' . $topic_data['topic_id'] . '
  60. AND user_id = ' . $user->data['user_id'];
  61.  
  62. $db->sql_query($sql);
  63. }
  64. elseif(!$check)
  65. {
  66. $sql = 'INSERT INTO ' . TOPICS_EVALUATION_TABLE . ' (topic_id, evaluation, user_id) VALUES ("' . $topic_data['topic_id'] . '", "' . $vote . '", "' . $user->data['user_id'] . '")';
  67. $db->sql_query($sql);
  68. }
  69. }
  70. redirect(append_sid($phpbb_root_path . 'viewtopic.' . $phpEx, 'f=' . $topic_data['forum_id'] . '&amp;t=' . $topic_data['topic_id'] . '&amp;start=' . request_var('start', 0)));
  71. }
  72. //
  73. // topic_data['forum_evaluation'] = How many stars should be displayed for evaluation
  74. // evaluation['evaluation'] = The currend evaluation of the topic
  75. //
  76. $template->assign_vars(array(
  77. 'EVALUATION_STARS' => $topic_data['forum_evaluation'],
  78. 'EVALUATION_RESULT_FLOOR' => floor($evaluation['ergebnis']),
  79. 'EVALUATION_RESULT_CEIL' => ceil($evaluation['ergebnis']),
  80. 'EVALUATION_RESULT' => ($evaluation['ergebnis'] > 0) ? $evaluation['ergebnis'] : 0.01, // not Null because it can be translated to ''
  81. 'EVALUATION_IMG_LIGHT' => $user->img('icon_evaluation_light', '', false, '', 'src'),
  82. 'EVALUATION_IMG_HALF' => $user->img('icon_evaluation_half', '', false, '', 'src'),
  83. 'EVALUATION_IMG_DARK' => $user->img('icon_evaluation_dark', '', false, '', 'src'),
  84. 'EVALUATION_LINK' => append_sid($phpbb_root_path . 'viewtopic.' . $phpEx, 'f=' . $topic_data['forum_id'] . '&t=' . $topic_data['topic_id'] . '&start=' . intval($start)))
  85. ); // Here above no &amp; because javascript with window.location.href does not like &amp; The href only works with &
  86. $mouse = ' name="evaluate%u" onClick="eval_mouse_click(%u)" onMouseOver="eval_mouse_over(%u, true)" onMouseOut="eval_mouse_over(%u, false)" style="cursor:pointer"';
  87. }
  88. }
  89. $user->add_lang('mods/evaluation');
  90.  
  91. if($auth->acl_get('f_evaluation_see', $topic_data['forum_id']))
  92. {
  93. if(isset($evaluation['evaluation']) && $evaluation['evaluation'] == 1) // Has he already evaluated and evaluated with one star?
  94. {
  95. $own_evaluation = $user->lang['YOUR_EVALUATION1'];
  96. }
  97. elseif(isset($evaluation['evaluation']) && $evaluation['evaluation'] > 1) // Has he already evaluated and evaluated with two or more stars?
  98. {
  99. $own_evaluation = sprintf($user->lang['YOUR_EVALUATION2'], $evaluation['evaluation']);
  100. }
  101. else
  102. {
  103. $own_evaluation = '';
  104. }
  105. $alt = sprintf($user->lang['TOPIC_EVALUATION_RESULT'], $evaluation['anzahl'], $evaluation['ergebnis'], $own_evaluation);
  106.  
  107. for($i = 1; $i <= $topic_data['forum_evaluation']; $i++)
  108. {
  109. if($i <= $evaluation['ergebnis'])
  110. {
  111. $img = $user->img('icon_evaluation_light', $alt);
  112. }
  113. elseif(($i <= ceil($evaluation['ergebnis'])) && ((floor($evaluation['ergebnis']) + 0.4) <= $evaluation['ergebnis']))
  114. {
  115. $img = $user->img('icon_evaluation_half', $alt);
  116. }
  117. else
  118. {
  119. $img = $user->img('icon_evaluation_dark', $alt);
  120. }
  121. $out .= (empty($mouse)) ? $img : str_replace('/>', sprintf($mouse, $i, $i, $i, $i) . ' />', $img);
  122. }
  123. $template->assign_var('EVALUATION_IMG', $out);
  124. }
  125. }
  126. ?>
Advertisement
Add Comment
Please, Sign In to add comment