Codice PHP:
$sql = 'SELECT * FROM ' . CHALLENGE_TABLE . ' ORDER BY id DESC LIMIT ' . $start . ',' . $max_number_challenge_listing;
if (!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Could not read challenge information.', '', __LINE__, __FILE__, $sql);
}
while($row = $db->sql_fetchrow($result))
{
$id_challenge = $row['id'];
$challenge_control_state = control_state($row['state']);
$challenge_state = $challenge_control_state['state'];
$image_status = $challenge_control_state['image_status'];
$message = $challenge_control_state['message'];
$today_date = create_date('d', time(), $board_config['board_timezone']);
$challenge_days_accept = $row['days_accept'];
$challenge_days_vote = $row['days_vote'];
$challenge_days_send_image = $row['days_send_image'];
$today_date = create_date('Y/m/j', time(), $board_config['board_timezone']);
$challenge_date_day_launch = create_date('Y/m/j', $row['date_launch'], $board_config['board_timezone']);
$challenge_date_plus_days_accept = create_date('Y/m/' . (create_date('j', $row['date_launch'], $board_config['board_timezone']) + $challenge_days_accept), $row['date_launch'], $board_config['board_timezone']);
$challenge_date_plus_days_vote = create_date('Y/m/' . (create_date('j', $row['date_launch'], $board_config['board_timezone']) + $challenge_days_vote), $row['date_launch'], $board_config['board_timezone']);
$challenge_date_plus_days_send_image = create_date('Y/m/' . (create_date('j', $row['date_launch'], $board_config['board_timezone']) + $challenge_days_send_image), $row['date_launch'], $board_config['board_timezone']);
if($state_challenge == $CHALLENGE_STATE_WAIT)
{
if((today_date > $challenge_date_plus_days_accept) || (today_date > challenge_date_plus_days_send_image))
{
$sql = 'UPDATE ' . CHALLENGE_TABLE . ' SET state = ' . $CHALLENGE_STATE_ANNULLED . ' WHERE id = ' . $id_challenge;
if (!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Could not update state challenge.', '', __LINE__, __FILE__, $sql);
}
}
}
elseif($state_challenge == $CHALLENGE_STATE_OPEN)
{
if($today_date > $challenge_date_plus_days_vote)
{
$sql = 'UPDATE ' . CHALLENGE_TABLE . ' SET state = ' . $CHALLENGE_STATE_LOCKED . ' WHERE id = ' . $id_challenge;
if (!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Could not update state challenge.', '', __LINE__, __FILE__, $sql);
}
}
}
elseif($challenge_state == $CHALLENGE_STATE_WAIT_IMAGES)
{
if($today_date > $challenge_date_plus_days_send_image)
{
$sql = 'UPDATE ' . CHALLENGE_TABLE . ' SET state = ' . $CHALLENGE_STATE_ANNULLED . ' WHERE id = ' . $id_challenge;
if (!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Could not update state challenge.', '', __LINE__, __FILE__, $sql);
}
}
}
}
$sql = 'SELECT * FROM ' . CHALLENGE_TABLE . ' ORDER BY id DESC LIMIT ' . $start . ',' . $max_number_challenge_listing;
if (!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Could not read id challenge.', '', __LINE__, __FILE__, $sql);
}
while($row = $db->sql_fetchrow($result))
{
$template->set_filenames(array('body' => 'challenge_view_all_body.tpl'));
$id_challenge = $row['id'];
$challenge_control_state = control_state($row['state']);
$challenge_state = $challenge_control_state['state'];
$image_status = $challenge_control_state['image_status'];
$message = $challenge_control_state['message'];
$challenge_date_launch = create_date($board_config['default_dateformat'], $row['date_launch'], $board_config['board_timezone']);
$challenge_days_accept = $row['days_accept'];
$challenge_days_vote = $row['days_vote'];
$challenge_days_send_image = $row['days_send_image'];
$challenger_vote = $row['vote_challenger'];
$challenging_vote = $row['vote_challenging'];
$challenge_users_voted = $challenger_vote + $challenging_vote;
$challenge_user_percent_challenger = ($challenge_users_voted != 0) ? round((($challenger_vote * 100) / $challenge_users_voted)) : 50;
$challenge_user_percent_challenging = ($challenge_users_voted != 0) ? round((($challenging_vote * 100) / $challenge_users_voted)) : 50;
if($challenger_vote > $challenging_vote)
{
$color_vote_graphic_img_left_challenge = 'green';
$color_vote_graphic_img_left_challenging = 'red';
}
if($challenging_vote > $challenger_vote)
{
$color_vote_graphic_img_left_challenge = 'red';
$color_vote_graphic_img_left_challenging = 'green';
}
if($challenger_vote == $challenging_vote)
{
$color_vote_graphic_img_left_challenge = 'blue';
$color_vote_graphic_img_left_challenging = $color_vote_graphic_img_left_challenge;
}
$vote_graphic_img_left_challenge = $images['voting_graphic_' . $color_vote_graphic_img_left_challenge . '_left'];
$vote_graphic_img_body_challenge = $images['voting_graphic_' . $color_vote_graphic_img_left_challenge . '_body'];
$vote_graphic_img_right_challenging = $images['voting_graphic_' . $color_vote_graphic_img_left_challenging . '_right'];
$vote_graphic_img_body_challenging = $images['voting_graphic_' . $color_vote_graphic_img_left_challenging . '_body'];
$user_challenger_id = $row['id_challenger'];
$user_challenging_id = $row['id_challenging'];
$user_challenger_data = get_userdata($user_challenger_id);
$user_challenger_data_link_username = colorize_username($user_challenger_data['user_id'], $user_challenger_data['username'], $user_challenger_data['user_color'], $user_challenger_data['user_active']);
$user_challenger_data_username = $user_challenger_data['username'];
$user_challenger_data_avatar = user_get_avatar($user_challenger_data['user_id'], $user_challenger_data['user_level'], $user_challenger_data['user_avatar'], $user_challenger_data['user_avatar_type'], $user_challenger_data['user_allowavatar']);
$user_challenging_data = get_userdata($user_challenging_id);
$user_challenging_data_link_username = colorize_username($user_challenging_data['user_id'], $user_challenging_data['username'], $user_challenging_data['user_color'], $user_challenging_data['user_active']);
$user_challenging_data_username = $user_challenging_data['username'];
$user_challenging_data_avatar = user_get_avatar($user_challenging_data['user_id'], $user_challenging_data['user_level'], $user_challenging_data['user_avatar'], $user_challenging_data['user_avatar_type'], $user_challenging_data['user_allowavatar']);
$server_url = create_server_url();
if ($board_config['url_rw'] == 1)
{
$server_url . 'challenge-' . make_url_friendly($user_challenger_data_username . '-vs-' . $user_challenging_data_username) . '-id-' . $id_challenge . '.html';
}
else
{
$url_challenge_details = U_CHALLENGE . '?' . $PARAMETER_ID . '=' . $id_challenge;
}
$challenge_type = control_type($row['type_challenge']);
$challenge_control_state = control_state($row['state']);
$challenge_state = $challenge_control_state['state'];
$image_status = $challenge_control_state['image_status'];
$message = $challenge_control_state['message'];
$template->assign_block_vars('challenge', array(
'MODE_VIEW' => MODE_VIEW_CHALLENGE,
'ID_CHALLENGE' => $id_challenge,
'CHALLENGE_STATE' => $challenge_state,
'CHALLENGE_TYPE' => $challenge_type,
'DATE_LAUNCH' => $challenge_date_launch,
'USER_VOTED' => $challenge_users_voted,
'USER_VOTED_CHALLENGER' => $challenge_user_percent_challenger,
'USER_VOTED_CHALLENGING' => $challenge_user_percent_challenging,
'DAYS_VOTE' => $challenge_days_vote,
'DAYS_ACCEPT' => $challenge_days_accept,
'DAYS_SEND_IMAGE' => $challenge_days_send_image,
'LINK_USERNAME_CHALLENGER' => $user_challenger_data_link_username,
'USERNAME_CHALLENGER' => $user_challenger_data_username,
'AVATAR_CHALLENGER' => $user_challenger_data_avatar,
'LINK_USERNAME_CHALLENGING' => $user_challenging_data_link_username,
'USERNAME_CHALLENGING' => $user_challenging_data_username,
'AVATAR_CHALLENGING' => $user_challenging_data_avatar,
'IMG_STATE' => $image_status,
'IMG_CHALLENGER_VOTE' => $challenger_user_image_vote,
'IMG_CHALLENGING_VOTE' => $challenging_user_image_vote,
'IMG_VOTE_L' => $vote_graphic_img_left_challenge,
'IMG_VOTE_R' => $vote_graphic_img_right_challenging,
'IMG_VOTE_BODY_CHALLENGE' => $vote_graphic_img_body_challenge,
'IMG_VOTE_BODY_CHALLENGING' => $vote_graphic_img_body_challenging,
'U_DETAILS' => $url_challenge_details,
));
}
Però sembra non andare