Seite 1 von 1

phpbb_fetch_all : Ergebnis auch anzeigen

Verfasst: 01.08.2005 21:42
von EnzephaloN
Hallo Leute

Ich arbeite immernoch an meiner Version von php_fetch_all im Bereich polls.php.

Als Erweiterung möchte ich, daß das Ergebnis der Umfrage angezeigt wird, wenn: der User nicht angemeldet ist, der Poll beendet ist oder er schon abgestimmt hat.

Das Problem: Bei mir zeigt er garnix an. Ich habe folgende polls_on_index.php gebaut:

Code: Alles auswählen

<?
define ('IN_PHPBB', true);
define('HEADER_INC', false);
$phpbb_root_path = '../forum/';
if (!file_exists($phpbb_root_path . 'extension.inc'))
{
    die ('<tt><b>phpBB Fetch All:</b>
          $phpbb_root_path is wrong and does not point to your forum.</tt>');
}
include_once ('extension.inc');
include_once ('common.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/common.' . $phpEx);
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);

include($phpbb_root_path. 'mods/phpbb_fetch_all/polls.php');
$vote = phpbb_fetch_poll_bt(56);
if ($vote)                                                       
   {
     if ($user_voted OR $poll_expired OR !$is_auth['auth_vote'] OR $forum_topic_data['topic_status'] = TOPIC_LOCKED )
     {
         echo'<table cellspacing="0" cellpadding="2" border="0" width="100%">
		 	<tr> 
		 	  <td align="center" class="textnormalohnerahmen" width="100%">' . $vote['vote_text'] . '</td>
		 	</tr><tr><td>
		 		<table cellspacing="0" cellpadding="0" border="0">';
         $vote_results_sum = 0;

			for($i = 0; $i < $vote_options; $i++)
			{
				$vote_results_sum += $vote_info[$i]['vote_result'];
			}

			$vote_graphic = 0;
			$vote_graphic_max = count($images['voting_graphic']);
			  
         for($i = 0; $i < $vote_options; $i++)
		{
				$vote_percent = ( $vote_results_sum > 0 ) ? $vote_info[$i]['vote_result'] / $vote_results_sum : 0;
				$vote_graphic_length = round($vote_percent * $board_config['vote_graphic_length']);

				$vote_graphic_img = $images['voting_graphic'][$vote_graphic];
				$vote_graphic = ($vote_graphic < $vote_graphic_max - 1) ? $vote_graphic + 1 : 0;

				if ( count($orig_word) )
				{
					$vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
				}
				$vote_percent_self = sprintf("%.1d%%", ($vote_percent * 100));
			echo' <tr>
			        <td colspan="4">' . $vote_info[$i]['vote_option_text'] . '</td>
			      </tr>
				  <tr> 
					<td><img src="' . $phpbb_root_path . 'templates/AdInfinitum/images/vote_lcap.gif" width="4" alt="" height="12" ></td>
					<td><img src="' . $phpbb_root_path . 'templates/AdInfinitum/images/voting_bar.gif" width="' . $vote_graphic_length . ' " height="12" alt="'. $vote_percent_self .'" ></td>
    				<td><img src="' . $phpbb_root_path . 'templates/AdInfinitum/images/vote_rcap.gif" width="4" alt="" height="12" ></td>
    				<td>' . $vote_percent_self . '</td>
				  </tr>';
		 }
			echo'</table>
			  </td>
			</tr>
			<tr>
			 <td class="textnormalohnerahmen" align="center"><a href="' . $phpbb_root_path . 'viewtopic.php?t=56">Zum Thread im Forum</a>
			 </td>
			</tr> 
		  </table>';
       } 
     else
     {
         echo '<div class="textnormalohnerahmen">'.$vote['vote_text'].'</div>';
         echo '<form method="post" action="' . $phpbb_root_path . 'posting.php?t=' . $vote['topic_id'] . '">';
         for ($i = 0; $i < count($vote['options']); $i++)
         {
             echo '<div class="textnormalohnerahmen"><input type="radio" name="vote_id" value="'.$vote['options'][$i]['vote_option_id'] . '">'.$vote['options'][$i]['vote_option_text'].'</div>';
         }

         if ($userdata['session_logged_in']) 
         {
           echo'<input type="submit" class="mainoption" name="submit" value="' . $lang['Submit_vote'] . '">'; 
           echo'<input type="hidden" name="topic_id" value="' . $vote['topic_id'] . '">';
           echo'<input type="hidden" name="mode" value="vote">';
         }
         else 
         { 
           echo'<div class="textnormalohnerahmen" align="center"><span class="gensmall">' . $lang['Rules_vote_cannot'] . '</span></div>';
         }
         echo '</form>';
     }
echo '<table width="100%">
       <tr>
         <td align="center" class="textnormalohnerahmen">
             Nur im Forum registrierte und angemeldete User k&ouml;nnen abstimmen
         </td>
       </tr>
      </table>';
   }
phpbb_disconnect();  
?>
dann habe ich an der polls.php rumgebaut

Code: Alles auswählen

function phpbb_fetch_poll_bt($topic_id = null)
{
	global $CFG;

	if (!isset($topic_id))
	{
		return;
	}

	$sql = 'SELECT f.*, p.*, pt.*, t.*, u.*, vv.*, vr.*, vd.*
				FROM ' . TOPICS_TABLE     . ' AS t,
					 ' . USERS_TABLE      . ' AS u,
					 ' . POSTS_TEXT_TABLE . ' AS pt,
					 ' . POSTS_TABLE      . ' AS p,
					 ' . FORUMS_TABLE     . ' AS f,
					 ' . VOTE_DESC_TABLE  . ' AS vd,
					 ' . VOTE_VOTERS      . ' AS vv,
					 ' . VOTE_RESULTS     . ' AS vr
				WHERE vd.topic_id = ' . $topic_id . '
					AND t.topic_poster = u.user_id
					AND t.topic_first_post_id = pt.post_id
					AND t.topic_first_post_id = p.post_id
					AND t.topic_status <> 1
					AND t.topic_status <> 2
					AND t.topic_vote = 1
					AND t.forum_id = f.forum_id
					AND t.topic_id = vd.topic_id
					AND u.user_id = vv.vote_user_id
					AND vr.vote_result = vr.vote_result';
					
	

	$sql .= '
				ORDER BY p.post_time DESC
				LIMIT 0,1';

	$result = phpbb_fetch_row($sql);

	if ($result)
	{
		//
		// perform an auth check if requested
		//

		if ($CFG['auth_check'])
		{
			phpbb_get_auth_list();

			if (!in_array($result['forum_id'], $CFG['auth_list']))
			{
				return;
			}
		}

		$sql = 'SELECT *
					FROM ' . VOTE_RESULTS_TABLE . '
					WHERE vote_id = ' . $result['vote_id'] . '
					ORDER BY vote_option_id';

		 $result['options'] = phpbb_fetch_rows($sql);
	}

	return $result;
} 
Aber das klappt garnicht. Kommt ein mysql-Fehler.

Hat jemand schon diese Erweiterung gebaut? Dann muß ich mich da nicht durchgraben, oder jemand eine Idee wo ich hier die Fehler mache?

Dankebar
EnzephaloN

Verfasst: 02.08.2005 14:23
von EnzephaloN
Ok, einige Veränderungen!

die polls.php ist wieder normal.

die polls_on_index.php sieht nun so aus:

Code: Alles auswählen

<?
define ('IN_PHPBB', true);
define('HEADER_INC', false);
$phpbb_root_path = '../forum/';
if (!file_exists($phpbb_root_path . 'extension.inc'))
{
    die ('<tt><b>phpBB Fetch All:</b>
          $phpbb_root_path is wrong and does not point to your forum.</tt>');
}
include_once ('extension.inc');
include_once ('common.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/common.' . $phpEx);
//INTRO
$topic_id = $post_id = 0;
if ( isset($HTTP_GET_VARS[POST_TOPIC_URL]) )
{
	$topic_id = intval($HTTP_GET_VARS[POST_TOPIC_URL]);
}
else if ( isset($HTTP_GET_VARS['topic']) )
{
	$topic_id = intval($HTTP_GET_VARS['topic']);
}

if ( isset($HTTP_GET_VARS[POST_POST_URL]))
{
	$post_id = intval($HTTP_GET_VARS[POST_POST_URL]);
}


$start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;

if ( !isset($topic_id) && !isset($post_id) )
{
	message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
}

//WAR SCHON DA
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);


//EINGELOGGT PRÜFEN
$is_auth = array();
$is_auth = auth(AUTH_ALL, $forum_id, $userdata, $forum_topic_data);

if( !$is_auth['auth_view'] || !$is_auth['auth_read'] )
{
	if ( !$userdata['session_logged_in'] )
	{
		$redirect = ( isset($post_id) ) ? POST_POST_URL . "=$post_id" : POST_TOPIC_URL . "=$topic_id";
		$redirect .= ( isset($start) ) ? "&start=$start" : '';
		redirect(append_sid("login.$phpEx?redirect=viewtopic.$phpEx&$redirect", true));
	}

	$message = ( !$is_auth['auth_view'] ) ? $lang['Topic_post_not_exist'] : sprintf($lang['Sorry_auth_read'], $is_auth['auth_read_type']);

	message_die(GENERAL_MESSAGE, $message);
}
//COOKIE SETZEN!!
if ( $userdata['session_logged_in'] )
{
	$tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
	$tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();

	if ( !empty($tracking_topics[$topic_id]) && !empty($tracking_forums[$forum_id]) )
	{
		$topic_last_read = ( $tracking_topics[$topic_id] > $tracking_forums[$forum_id] ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
	}
	else if ( !empty($tracking_topics[$topic_id]) || !empty($tracking_forums[$forum_id]) )
	{
		$topic_last_read = ( !empty($tracking_topics[$topic_id]) ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
	}
	else
	{
		$topic_last_read = $userdata['user_lastvisit'];
	}

	if ( count($tracking_topics) >= 150 && empty($tracking_topics[$topic_id]) )
	{
		asort($tracking_topics);
		unset($tracking_topics[key($tracking_topics)]);
	}

	$tracking_topics[$topic_id] = time();

	setcookie($board_config['cookie_name'] . '_t', serialize($tracking_topics), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
}

//JETZ GEHTS LOS

include($phpbb_root_path. 'mods/phpbb_fetch_all/polls.php');
$vote = phpbb_fetch_poll_bt(56);
   
   	$sql = "SELECT vd.vote_id, 
   	               vd.vote_text, 
   	               vd.vote_start, 
   	               vd.vote_length, 
   	               vr.vote_option_id, 
   	               vr.vote_option_text, 
   	               vr.vote_result
		FROM " . VOTE_DESC_TABLE . " vd, 
		     " . VOTE_RESULTS_TABLE . " vr
		WHERE vd.topic_id = $topic_id
			AND vr.vote_id = vd.vote_id
		ORDER BY vr.vote_option_id ASC";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, "Could not obtain vote data for this topic", '', __LINE__, __FILE__, $sql);
	}

	if ( $vote_info = $db->sql_fetchrowset($result) )
	{
		$db->sql_freeresult($result);
		$vote_options = count($vote_info);

		$vote_id = $vote_info[0]['vote_id'];
		$vote_title = $vote_info[0]['vote_text'];

		$sql = "SELECT vote_id,
		               vote_user_id
			FROM " . VOTE_USERS_TABLE . "
			WHERE vote_id = $vote_id
				AND vote_user_id = " . intval($userdata['user_id']);
		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, "Could not obtain user vote data for this topic", '', __LINE__, __FILE__, $sql);
		}
   
		$user_voted = ( $row = $db->sql_fetchrow($result) ) ? TRUE : 0;
		$db->sql_freeresult($result);

   $my_user_id = $userdata['user_id'];
   $had_voted = $result['vote_user_id'];

		if ( isset($HTTP_GET_VARS['vote']) || isset($HTTP_POST_VARS['vote']) )
		{
			$view_result = ( ( ( isset($HTTP_GET_VARS['vote']) ) ? $HTTP_GET_VARS['vote'] : $HTTP_POST_VARS['vote'] ) == 'viewresult' ) ? TRUE : 0;
		}
		else
		{
			$view_result = 0;
		}

		$poll_expired = ( $vote_info[0]['vote_length'] ) ? ( ( $vote_info[0]['vote_start'] + $vote_info[0]['vote_length'] < time() ) ? TRUE : 0 ) : 0;


   }
   
   
     if ($user_voted || $poll_expired || !$is_auth['auth_vote'] || $forum_topic_data['topic_status'] == TOPIC_LOCKED || $my_user_id == $had_voted )
     {
         echo'<table cellspacing="0" cellpadding="2" border="0" width="100%">
		 	<tr> 
		 	  <td align="center" class="textnormalohnerahmen" width="100%">' . $vote['vote_text'] . '</td>
		 	</tr><tr><td>
		 	<table cellspacing="0" cellpadding="0" border="0">';
            $vote_results_sum = 0;

			for($i = 0; $i < $vote_options; $i++)
			{
				$vote_results_sum += $vote_info[$i]['vote_result'];
			}

			$vote_graphic = 0;
			$vote_graphic_max = count($images['voting_graphic']);
			  
         for($i = 0; $i < $vote_options; $i++)
		 {
				$vote_percent = ( $vote_results_sum > 0 ) ? $vote_info[$i]['vote_result'] / $vote_results_sum : 0;
				$vote_graphic_length = round($vote_percent * $board_config['vote_graphic_length']);

				$vote_graphic_img = $images['voting_graphic'][$vote_graphic];
				$vote_graphic = ($vote_graphic < $vote_graphic_max - 1) ? $vote_graphic + 1 : 0;

				if ( count($orig_word) )
				{
					$vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
				}
				$vote_percent_self = sprintf("%.1d%%", ($vote_percent * 100));
			echo' <tr>
			        <td colspan="4">' . $vote_info[$i]['vote_option_text'] . '</td>
			      </tr>
				  <tr> 
					<td><img src="' . $phpbb_root_path . 'templates/AdInfinitum/images/vote_lcap.gif" width="4" alt="" height="12" ></td>
					<td><img src="' . $phpbb_root_path . 'templates/AdInfinitum/images/voting_bar.gif" width="' . $vote_graphic_length . ' " height="12" alt="'. $vote_percent_self .'" ></td>
    				<td><img src="' . $phpbb_root_path . 'templates/AdInfinitum/images/vote_rcap.gif" width="4" alt="" height="12" ></td>
    				<td>' . $vote_percent_self . '</td>
				  </tr>';
		 }
			echo'</table>
			  </td>
			</tr>
			<tr>
			 <td class="textnormalohnerahmen" align="center"><a href="' . $phpbb_root_path . 'viewtopic.php?t=56">Zum Thread im Forum</a>
			 </td>
			</tr> 
		  </table>';
       } 
     else
     {
            echo'<table cellspacing="0" cellpadding="2" border="0" width="100%">
		 	<tr> 
		 	  <td align="center" class="textnormalohnerahmen" width="100%">' . $vote['vote_text'] . '</td>
		 	</tr>';

         echo '<tr><td class="textnormalohnerahmen" align="left">';
         echo '<form method="post" action="' . $phpbb_root_path . 'posting.php?mode=vote&t=' . $vote['topic_id'] . '">';
         for ($i = 0; $i < count($vote['options']); $i++)
         {
             echo '<div class="textnormalohnerahmen"><input type="radio" name="vote_id" value="'.$vote['options'][$i]['vote_option_id'] . '">'.$vote['options'][$i]['vote_option_text'].'</div>';
         }

         if ($userdata['session_logged_in']) 
         {
           echo'<input type="submit" class="mainoption" name="submit" value="' . $lang['Submit_vote'] . '">'; 
           echo'<input type="hidden" name="topic_id" value="' . $vote['topic_id'] . '">';
           echo'<input type="hidden" name="mode" value="vote">';
         }
         else 
         { 
           echo'<div class="textnormalohnerahmen" align="center"><span class="gensmall">' . $lang['Rules_vote_cannot'] . '</span></div>';
         }
         echo '</form></td></tr></table>';
     }
echo '<table width="100%">
       <tr>
         <td align="center" class="textnormalohnerahmen">
             Nur im Forum registrierte und angemeldete User k&ouml;nnen abstimmen
         </td>
       </tr>
      </table>';
   
phpbb_disconnect();  
?>
Problem: wenn man nicht abgestimmt hat gehts - man kann auch abstimmen. Aber wenn man abgestimmt hat, dann sieht man garnichts - nur die Überschrift und den Link auf den Beitrag im Forum. Die Balkendiagramme werden einfach nicht angezeigt.
Eigentlich komisch, da ich den Quelltext fast 1:1 aus der viewtopics.php übernommen habe.

Sieht jemand den Fehler?

EnzephaloN