| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
<span class="code-comment"> * admin_voting.php |
|---|
| 4 |
* ------------------- |
|---|
| 5 |
* begin : Saturday, August 24, 2002 |
|---|
| 6 |
* copyright : (C) 2002 ErDrRon |
|---|
| 7 |
* email : ErDrRon@aol.com |
|---|
| 8 |
* |
|---|
| 9 |
* $Id: admin_voting.php,v 1.1.8 12/04/2003, 13:35:00 erdrron Exp $ |
|---|
| 10 |
* |
|---|
| 11 |
***************************************************************************/ |
|---|
| 12 |
|
|---|
| 13 |
/*************************************************************************** |
|---|
| 14 |
* |
|---|
| 15 |
* This program is free software; you can redistribute it and/or modify |
|---|
| 16 |
* it under the terms of the GNU General Public License as published by |
|---|
| 17 |
* the Free Software Foundation; either version 2 of the License, or |
|---|
| 18 |
* (at your option) any later version. |
|---|
| 19 |
* |
|---|
| 20 |
***************************************************************************/ |
|---|
| 21 |
|
|---|
| 22 |
if( !empty($setmodules) )</span> |
|---|
| 23 |
<span class="code-keyword">{ |
|---|
| 24 |
$filename = basename(__FILE__); |
|---|
| 25 |
$module['poll admin']['poll admin'] = $filename; |
|---|
| 26 |
$module['poll admin']['create_new_poll'] = $filename . '?mode=add'; |
|---|
| 27 |
return; |
|---|
| 28 |
} |
|---|
| 29 |
|
|---|
| 30 |
define('IN_PHPBB', 1); |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
<span class="code-comment">// |
|---|
| 34 |
$root_path = './../';</span> |
|---|
| 35 |
<span class="code-lang">require($root_path . 'extension.inc'); |
|---|
| 36 |
require('./pagestart.' . $phpEx); |
|---|
| 37 |
include($root_path . 'languages/lang_' . $config['default_lang'] . '/lang_admin_voting.' . $phpEx); |
|---|
| 38 |
|
|---|
| 39 |
$mode = request_var('mode', '');</span> |
|---|
| 40 |
<span class="code-lang"> |
|---|
| 41 |
if ( $mode == 'delete' ) { |
|---|
| 42 |
$vote_id = ( isset($_GET['vote_id']) ? intval($_GET['vote_id']) : 0 ); |
|---|
| 43 |
|
|---|
| 44 |
$sql = "SELECT vote_id |
|---|
| 45 |
FROM " . VOTE_RESULTS_TABLE . " |
|---|
| 46 |
WHERE vote_id = $vote_id |
|---|
| 47 |
ORDER BY vote_option_id ASC"; |
|---|
| 48 |
$result = $db->sql_query($sql); |
|---|
| 49 |
|
|---|
| 50 |
if ($row = $db->sql_fetchrow($result)) { |
|---|
| 51 |
$sql = 'DELETE FROM ' . VOTE_DESC_TABLE . ' WHERE vote_id = ' . $vote_id . ' AND topic_id = 0'; |
|---|
| 52 |
$db->sql_query($sql); |
|---|
| 53 |
|
|---|
| 54 |
$sql = 'DELETE FROM ' . VOTE_RESULTS_TABLE . ' WHERE vote_id = ' . $vote_id; |
|---|
| 55 |
$db->sql_query($sql); |
|---|
| 56 |
|
|---|
| 57 |
$sql = 'DELETE FROM ' . VOTE_USERS_TABLE . ' WHERE vote_id = ' . $vote_id; |
|---|
| 58 |
$db->sql_query($sql); |
|---|
| 59 |
|
|---|
| 60 |
$cache->destroy('sql', VOTE_DESC_TABLE); |
|---|
| 61 |
trigger_error($lang['poll_deleted_sucefully'] . '<br /><br />' . sprintf($lang['click_return_admin_polls'], '<a href="' . append_sid("admin_voting.$phpEx") . '">', '</a>')); |
|---|
| 62 |
|
|---|
| 63 |
} |
|---|
| 64 |
else { |
|---|
| 65 |
trigger_error('Invalid poll id'); |
|---|
| 66 |
} |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
if ( $mode == 'show_poll_results' ) { |
|---|
| 70 |
$poll_id = request_var('poll_id', 0); |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
$sql = "SELECT DISTINCT u.uid, u.name AS username, u.class, u.warneduntil, u.enabled, u.donor, u.parked, vote_id, vote_user_id, vote_cast |
|---|
| 74 |
FROM " . USERS_TABLE . " AS u , " . VOTE_USERS_TABLE . " AS vv |
|---|
| 75 |
WHERE u.uid = vv.vote_user_id AND vote_id = " . $poll_id; |
|---|
| 76 |
$result = $db->sql_query($sql); |
|---|
| 77 |
while ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 78 |
$voter_arr[$row['vote_cast']][] = parse_username($row); |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
$sql = "SELECT vote_option_id, vote_option_text, vote_result FROM ". VOTE_RESULTS_TABLE . " WHERE vote_id = " . $poll_id; |
|---|
| 83 |
$result = $db->sql_query($sql); |
|---|
| 84 |
|
|---|
| 85 |
while ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 86 |
$option_arr[$row['vote_option_id']] = $row; |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
$result_ary = array(); |
|---|
| 90 |
|
|---|
| 91 |
foreach( $option_arr AS $vote_option_id => $elem ) { |
|---|
| 92 |
$option_text = $elem["vote_option_text"]; |
|---|
| 93 |
$option_result = $elem["vote_result"]; |
|---|
| 94 |
$user = ( isset($voter_arr[$vote_option_id]) ? $voter_arr[$vote_option_id] : array() ); |
|---|
| 95 |
$user = implode(', ', $user); |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
$result_ary[$option_text][] = array('result' => $option_result, 'users' => $user); |
|---|
| 99 |
} |
|---|
| 100 |
gc(json_encode(array('results' => $result_ary))); |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
if ( $mode == 'edit' || $mode == 'add' ) { |
|---|
| 104 |
$template->set_filenames(array('pollbody' => '../admin/admin_voting_body.tpl')); |
|---|
| 105 |
$template->assign_block_vars('edit', array()); |
|---|
| 106 |
|
|---|
| 107 |
$vote_id = ( isset($_GET['vote_id']) ? intval($_GET['vote_id']) : 0 ); |
|---|
| 108 |
$poll_title = ( !empty($_POST['poll_title']) ) ? htmlspecialchars(trim(stripslashes($_POST['poll_title']))) : ''; |
|---|
| 109 |
$poll_length = ( isset($_POST['poll_length']) ) ? max(0, intval($_POST['poll_length'])) : 0; |
|---|
| 110 |
|
|---|
| 111 |
$poll_options = array(); |
|---|
| 112 |
if ( !empty($_POST['poll_option_text']) ) { |
|---|
| 113 |
while( list($option_id, $option_text) = @each($_POST['poll_option_text']) ) { |
|---|
| 114 |
if( isset($_POST['del_poll_option'][$option_id]) ) |
|---|
| 115 |
{ |
|---|
| 116 |
unset($poll_options[$option_id]); |
|---|
| 117 |
} |
|---|
| 118 |
else if ( !empty($option_text) ) |
|---|
| 119 |
{ |
|---|
| 120 |
$poll_options[intval($option_id)] = htmlspecialchars(trim(stripslashes($option_text))); |
|---|
| 121 |
} |
|---|
| 122 |
} |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
if ( !empty($_POST['add_poll_option_text']) ) |
|---|
| 126 |
{ |
|---|
| 127 |
$poll_options[] = htmlspecialchars(trim(stripslashes($_POST['add_poll_option_text']))); |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
if ( isset($_POST['post']) && !empty($poll_title) && sizeof($poll_options) >= 2 ) |
|---|
| 132 |
{ |
|---|
| 133 |
$current_time = time(); |
|---|
| 134 |
|
|---|
| 135 |
$sql = ( $mode == 'add' ? "INSERT INTO " . VOTE_DESC_TABLE . " (topic_id, vote_text, vote_start, vote_length) VALUES (0, '$poll_title', $current_time, " . ($poll_length * 86400) . ")" : "UPDATE " . VOTE_DESC_TABLE . " SET vote_text = '$poll_title', vote_length = " . ($poll_length * 86400) . " WHERE topic_id = 0 AND vote_id = " . $vote_id ); |
|---|
| 136 |
$db->sql_query($sql); |
|---|
| 137 |
$cache->destroy('sql', VOTE_DESC_TABLE); |
|---|
| 138 |
|
|---|
| 139 |
$delete_option_sql = ''; |
|---|
| 140 |
$old_poll_result = array(); |
|---|
| 141 |
|
|---|
| 142 |
if ( $mode == 'edit' ) { |
|---|
| 143 |
|
|---|
| 144 |
$sql = "SELECT vote_option_id, vote_result |
|---|
| 145 |
FROM " . VOTE_RESULTS_TABLE . " |
|---|
| 146 |
WHERE vote_id = $vote_id |
|---|
| 147 |
ORDER BY vote_option_id ASC"; |
|---|
| 148 |
$result = $db->sql_query($sql); |
|---|
| 149 |
|
|---|
| 150 |
while ($row = $db->sql_fetchrow($result)) |
|---|
| 151 |
{ |
|---|
| 152 |
$old_poll_result[$row['vote_option_id']] = $row['vote_result']; |
|---|
| 153 |
if (!isset($poll_options[$row['vote_option_id']])) |
|---|
| 154 |
{ |
|---|
| 155 |
$delete_option_sql .= ($delete_option_sql != '') ? ', ' . $row['vote_option_id'] : $row['vote_option_id']; |
|---|
| 156 |
} |
|---|
| 157 |
} |
|---|
| 158 |
} |
|---|
| 159 |
else { |
|---|
| 160 |
$vote_id = $db->sql_nextid(); |
|---|
| 161 |
} |
|---|
| 162 |
|
|---|
| 163 |
@reset($poll_options); |
|---|
| 164 |
|
|---|
| 165 |
$poll_option_id = 1; |
|---|
| 166 |
while (list($option_id, $option_text) = each($poll_options)) |
|---|
| 167 |
{ |
|---|
| 168 |
if (!empty($option_text)) |
|---|
| 169 |
{ |
|---|
| 170 |
$option_text = $db->sql_escape($option_text); |
|---|
| 171 |
$poll_result = ( $mode == 'edit' && isset($old_poll_result[$option_id])) ? $old_poll_result[$option_id] : 0; |
|---|
| 172 |
|
|---|
| 173 |
$sql = ( $mode != 'edit' || !isset($old_poll_result[$option_id])) ? "INSERT INTO " . VOTE_RESULTS_TABLE . " (vote_id, vote_option_id, vote_option_text, vote_result) VALUES ($vote_id, $poll_option_id, '$option_text', $poll_result)" : "UPDATE " . VOTE_RESULTS_TABLE . " SET vote_option_text = '$option_text', vote_result = $poll_result WHERE vote_option_id = $option_id AND vote_id = $vote_id"; |
|---|
| 174 |
$db->sql_query($sql); |
|---|
| 175 |
$poll_option_id++; |
|---|
| 176 |
} |
|---|
| 177 |
} |
|---|
| 178 |
|
|---|
| 179 |
if ($delete_option_sql != '') |
|---|
| 180 |
{ |
|---|
| 181 |
$sql = "DELETE FROM " . VOTE_RESULTS_TABLE . " |
|---|
| 182 |
WHERE vote_option_id IN ($delete_option_sql) |
|---|
| 183 |
AND vote_id = $vote_id"; |
|---|
| 184 |
$db->sql_query($sql); |
|---|
| 185 |
$sql = "DELETE FROM " . VOTE_USERS_TABLE . " |
|---|
| 186 |
WHERE vote_cast IN ($delete_option_sql) |
|---|
| 187 |
AND vote_id = $vote_id"; |
|---|
| 188 |
$db->sql_query($sql); |
|---|
| 189 |
} |
|---|
| 190 |
trigger_error(( $mode == 'add' ? $lang['poll_added_sucefully'] : $lang['poll_edited_sucefully'] ) . '<br /><br />' . sprintf($lang['click_return_admin_polls'], '<a href="' . append_sid("admin_voting.$phpEx") . '">', '</a>')); |
|---|
| 191 |
} |
|---|
| 192 |
elseif ( !$poll_title && $mode == 'edit' ) { |
|---|
| 193 |
|
|---|
| 194 |
$sql = "SELECT * |
|---|
| 195 |
FROM " . VOTE_DESC_TABLE . " vd, " . VOTE_RESULTS_TABLE . " vr |
|---|
| 196 |
WHERE vd.topic_id = 0 |
|---|
| 197 |
AND vr.vote_id = vd.vote_id |
|---|
| 198 |
AND vr.vote_id = $vote_id |
|---|
| 199 |
ORDER BY vr.vote_option_id"; |
|---|
| 200 |
$result = $db->sql_query($sql); |
|---|
| 201 |
|
|---|
| 202 |
$poll_options = array(); |
|---|
| 203 |
$poll_results_sum = 0; |
|---|
| 204 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 205 |
$poll_title = $row['vote_text']; |
|---|
| 206 |
$poll_id = $row['vote_id']; |
|---|
| 207 |
$poll_length = $row['vote_length'] / 86400; |
|---|
| 208 |
do { |
|---|
| 209 |
$poll_options[$row['vote_option_id']] = $row['vote_option_text']; |
|---|
| 210 |
$poll_results_sum += $row['vote_result']; |
|---|
| 211 |
} |
|---|
| 212 |
while ( $row = $db->sql_fetchrow($result) ); |
|---|
| 213 |
} |
|---|
| 214 |
else { |
|---|
| 215 |
trigger_error('Invalid poll id'); |
|---|
| 216 |
} |
|---|
| 217 |
$db->sql_freeresult($result); |
|---|
| 218 |
} |
|---|
| 219 |
|
|---|
| 220 |
while( list($option_id, $option_text) = each($poll_options) ) { |
|---|
| 221 |
$template->assign_block_vars('edit.poll_option_rows', array( |
|---|
| 222 |
'POLL_OPTION' => str_replace('"', '"', $option_text), |
|---|
| 223 |
'S_POLL_OPTION_NUM' => $option_id) |
|---|
| 224 |
); |
|---|
| 225 |
} |
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
$template->assign_vars(array( |
|---|
| 230 |
'L_ADMIN_VOTE_TITLE' => $lang['admin_vote_title'], |
|---|
| 231 |
'L_ADMIN_VOTE_EXPLAIN' => ( $mode == 'edit' ? $lang['admin_vote_edit_poll_explain'] : $lang['admin_vote_add_poll_explain']), |
|---|
| 232 |
'L_ADD_A_POLL' => $lang['add_poll'], |
|---|
| 233 |
'L_POLL_QUESTION' => $lang['poll_question'], |
|---|
| 234 |
'L_POLL_OPTION' => $lang['poll_option'], |
|---|
| 235 |
'L_ADD_OPTION' => $lang['add_option'], |
|---|
| 236 |
'L_UPDATE_OPTION' => $lang['update'], |
|---|
| 237 |
'L_DELETE_OPTION' => $lang['delete'], |
|---|
| 238 |
'L_POLL_LENGTH' => $lang['poll_for'], |
|---|
| 239 |
'L_DAYS' => $lang['days'], |
|---|
| 240 |
'L_POLL_LENGTH_EXPLAIN' => $lang['poll_for_explain'], |
|---|
| 241 |
'L_POLL_DELETE' => $lang['delete_poll'], |
|---|
| 242 |
|
|---|
| 243 |
'S_MODE_ACTION' => append_sid('admin_voting.php?mode=' . ( $mode == 'edit' ? 'edit' : 'add' ) . '&vote_id=' . $vote_id), |
|---|
| 244 |
|
|---|
| 245 |
'POLL_TITLE' => $poll_title, |
|---|
| 246 |
'POLL_LENGTH' => $poll_length) |
|---|
| 247 |
); |
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
$template->display('pollbody'); |
|---|
| 251 |
include('./page_footer_admin.'.$phpEx); |
|---|
| 252 |
} |
|---|
| 253 |
else { |
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
// |
|---|
| 258 |
// Determine current starting row |
|---|
| 259 |
$start = ( isset($_GET['start']) ) ? intval($_GET['start']) : 0; |
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
if(isset($_GET['field']) || isset($_POST['field'])) |
|---|
| 263 |
{ |
|---|
| 264 |
$sort_field = (isset($_POST['field'])) ? $_POST['field'] : $_GET['field']; |
|---|
| 265 |
} |
|---|
| 266 |
else |
|---|
| 267 |
{ |
|---|
| 268 |
$sort_field = 'vote_id'; |
|---|
| 269 |
} |
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
if(isset($_POST['order'])) |
|---|
| 273 |
{ |
|---|
| 274 |
$sort_order = ($_POST['order'] == 'ASC') ? 'ASC' : 'DESC'; |
|---|
| 275 |
} |
|---|
| 276 |
elseif(isset($_GET['order'])) |
|---|
| 277 |
{ |
|---|
| 278 |
$sort_order = ($_GET['order'] == 'ASC') ? 'ASC' : 'DESC'; |
|---|
| 279 |
} |
|---|
| 280 |
else |
|---|
| 281 |
{ |
|---|
| 282 |
$sort_order = 'DESC'; |
|---|
| 283 |
} |
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
$sort_fields_text = array( |
|---|
| 287 |
$lang['sort_vote_id'], |
|---|
| 288 |
$lang['sort_poll_topic'], |
|---|
| 289 |
$lang['sort_vote_start'], |
|---|
| 290 |
$lang['sort_only_index'] |
|---|
| 291 |
); |
|---|
| 292 |
|
|---|
| 293 |
$sort_fields = array( |
|---|
| 294 |
'vote_id', |
|---|
| 295 |
'poll_topic', |
|---|
| 296 |
'vote_start', |
|---|
| 297 |
'topic_id' |
|---|
| 298 |
); |
|---|
| 299 |
|
|---|
| 300 |
if (empty($sort_field)) |
|---|
| 301 |
{ |
|---|
| 302 |
$sort_field = 'vote_id'; |
|---|
| 303 |
$sort_order = 'ASC'; |
|---|
| 304 |
} |
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
if (sizeof($sort_fields_text) > 0) |
|---|
| 308 |
{ |
|---|
| 309 |
$select_sort_field = '<select name="field">'; |
|---|
| 310 |
|
|---|
| 311 |
for($i = 0; $i < sizeof($sort_fields_text); $i++) |
|---|
| 312 |
{ |
|---|
| 313 |
$selected = ($sort_field == $sort_fields[$i]) ? ' selected="selected"' : ''; |
|---|
| 314 |
$select_sort_field .= '<option value="' . $sort_fields[$i] . '"' . $selected . '>' . $sort_fields_text[$i] . '</option>'; |
|---|
| 315 |
} |
|---|
| 316 |
$select_sort_field .= '</select>'; |
|---|
| 317 |
} |
|---|
| 318 |
|
|---|
| 319 |
if (!empty($sort_order)) |
|---|
| 320 |
{ |
|---|
| 321 |
$select_sort_order = '<select name="order">'; |
|---|
| 322 |
if($sort_order == 'ASC') |
|---|
| 323 |
{ |
|---|
| 324 |
$select_sort_order .= '<option value="ASC" selected="selected">' . $lang['sort_ascending'] . '</option><option value="DESC">' . $lang['sort_descending'] . '</option>'; |
|---|
| 325 |
} |
|---|
| 326 |
else |
|---|
| 327 |
{ |
|---|
| 328 |
$select_sort_order .= '<option value="ASC">' . $lang['sort_ascending'] . '</option><option value="DESC" selected="selected">' . $lang['sort_descending'] . '</option>'; |
|---|
| 329 |
} |
|---|
| 330 |
$select_sort_order .= '</select>'; |
|---|
| 331 |
} |
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
$order_by = ''; |
|---|
| 335 |
$extra_where = ''; |
|---|
| 336 |
|
|---|
| 337 |
switch($sort_field) |
|---|
| 338 |
{ |
|---|
| 339 |
case 'vote_id': |
|---|
| 340 |
$order_by = 'vote_id ' . $sort_order . ' LIMIT ' . $start . ", " . $config['posts_per_page']; |
|---|
| 341 |
break; |
|---|
| 342 |
case 'poll_topic': |
|---|
| 343 |
$order_by = 'vote_text ' . $sort_order . ' LIMIT ' . $start . ", " . $config['posts_per_page']; |
|---|
| 344 |
break; |
|---|
| 345 |
case 'vote_start': |
|---|
| 346 |
$order_by = 'vote_start ' . $sort_order . ' LIMIT ' . $start . ", " . $config['posts_per_page']; |
|---|
| 347 |
break; |
|---|
| 348 |
case 'topic_id': |
|---|
| 349 |
$extra_where = ' WHERE topic_id = 0'; |
|---|
| 350 |
$sort_field = 'vote_id'; |
|---|
| 351 |
$sort_order = 'ASC'; |
|---|
| 352 |
$order_by = 'vote_id ' . $sort_order . ' LIMIT ' . $start . ", " . $config['posts_per_page']; |
|---|
| 353 |
break; |
|---|
| 354 |
default: |
|---|
| 355 |
$sort_field = 'vote_id'; |
|---|
| 356 |
$sort_order = 'ASC'; |
|---|
| 357 |
$order_by = 'vote_id ' . $sort_order . ' LIMIT ' . $start . ", " . $config['posts_per_page']; |
|---|
| 358 |
break; |
|---|
| 359 |
} |
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
// |
|---|
| 363 |
// Assign page template |
|---|
| 364 |
$template->set_filenames(array('pollbody' => '../admin/admin_voting_body.tpl')); |
|---|
| 365 |
$template->assign_block_vars('viewresult', array()); |
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
$template->assign_vars(array( |
|---|
| 369 |
'S_FIELD_SELECT' => $select_sort_field, |
|---|
| 370 |
'S_ORDER_SELECT' => $select_sort_order, |
|---|
| 371 |
'S_CREATE_POLL_LINK' => append_sid('admin_voting.php?mode=add') |
|---|
| 372 |
)); |
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 |
$sql ="SELECT * |
|---|
| 376 |
FROM ". VOTE_DESC_TABLE . $extra_where . |
|---|
| 377 |
" ORDER BY " . $order_by; |
|---|
| 378 |
|
|---|
| 379 |
$result = $db->sql_query($sql); |
|---|
| 380 |
|
|---|
| 381 |
while ( $row = $db->sql_fetchrow($result) ) |
|---|
| 382 |
{ |
|---|
| 383 |
$topic_row_color = (($i % 2) == 0) ? $theme['td_class1'] : $theme['td_class2']; |
|---|
| 384 |
$vote_id = $row['vote_id']; |
|---|
| 385 |
$vote_text = ( $row['topic_id'] ? $row['vote_text'] : '<b>' . $row['vote_text'] . '</b>' ); |
|---|
| 386 |
$topic_id = $row['topic_id']; |
|---|
| 387 |
$vote_start = $row['vote_start']; |
|---|
| 388 |
$vote_length = $row['vote_length']; |
|---|
| 389 |
$vote_end = $vote_start + $vote_length; |
|---|
| 390 |
|
|---|
| 391 |
if (time() < $vote_end) |
|---|
| 392 |
{ |
|---|
| 393 |
$vote_duration = (date ("Y-m-d",$vote_start)) . " - " . (date ("Y-m-d",$vote_end)) . ' (' . $lang['ongoing'] . ')'; |
|---|
| 394 |
} |
|---|
| 395 |
else if ($vote_length == 0) |
|---|
| 396 |
{ |
|---|
| 397 |
$vote_duration = (date ("Y-m-d",$vote_start)) . ' - ' . $lang['infinite']; |
|---|
| 398 |
} |
|---|
| 399 |
else |
|---|
| 400 |
{ |
|---|
| 401 |
$vote_duration = (date ("Y-m-d",$vote_start)) . " - " . (date ("Y-m-d",$vote_end)) . ' (' . $lang['completed'] . ')'; |
|---|
| 402 |
} |
|---|
| 403 |
|
|---|
| 404 |
$user = ''; |
|---|
| 405 |
$users = ''; |
|---|
| 406 |
$user_option_arr = array(); |
|---|
| 407 |
|
|---|
| 408 |
if ( isset($voter_arr[$vote_id]) && sizeof($voter_arr[$vote_id]) ) |
|---|
| 409 |
{ |
|---|
| 410 |
foreach($voter_arr[$vote_id] as $user_id => $option_id) |
|---|
| 411 |
{ |
|---|
| 412 |
$_user = ( isset($user_arr[$user_id]) ? $user_arr[$user_id] : '' ); |
|---|
| 413 |
$user .= $_user . ', '; |
|---|
| 414 |
if ( isset($user_option_arr[$option_id]) ) { |
|---|
| 415 |
$user_option_arr[$option_id] .= $_user . ', '; |
|---|
| 416 |
} |
|---|
| 417 |
else { |
|---|
| 418 |
$user_option_arr[$option_id] = $_user . ', '; |
|---|
| 419 |
} |
|---|
| 420 |
} |
|---|
| 421 |
$user = substr($user, "0", strrpos($user, ", ")); |
|---|
| 422 |
} |
|---|
| 423 |
|
|---|
| 424 |
$template->assign_block_vars("viewresult.votes", array( |
|---|
| 425 |
'COLOR' => $topic_row_color, |
|---|
| 426 |
'LINK' => ( $topic_id ? $root_path . "phpbb2.php?page=viewtopic&t=$topic_id" : '' ), |
|---|
| 427 |
'EDIT_LINK' => ( $topic_id ? '' : append_sid('admin_voting.' . $phpEx . '?mode=edit&vote_id=' . $vote_id) ), |
|---|
| 428 |
'DELETE_LINK' => ( $topic_id ? '' : append_sid('admin_voting.' . $phpEx . '?mode=delete&vote_id=' . $vote_id) ), |
|---|
| 429 |
'DESCRIPTION' => $vote_text, |
|---|
| 430 |
'ENDDATE' => $vote_end, |
|---|
| 431 |
'VOTE_DURATION' => $vote_duration, |
|---|
| 432 |
'VOTE_ID' => $vote_id ) |
|---|
| 433 |
); |
|---|
| 434 |
|
|---|
| 435 |
} |
|---|
| 436 |
|
|---|
| 437 |
$num_polls = $i; |
|---|
| 438 |
|
|---|
| 439 |
// |
|---|
| 440 |
$sql = "SELECT count(*) AS total |
|---|
| 441 |
FROM " . VOTE_DESC_TABLE . $extra_where; |
|---|
| 442 |
|
|---|
| 443 |
$result = $db->sql_query($sql); |
|---|
| 444 |
|
|---|
| 445 |
if ( $total = $db->sql_fetchrow($result) ) |
|---|
| 446 |
{ |
|---|
| 447 |
$total_polls = $total['total']; |
|---|
| 448 |
$pagination = generate_pagination($admin_path . "admin_voting.$phpEx?mode=$sort_field&order=$sort_order", $total_polls, $config['posts_per_page'], $start). ' '; |
|---|
| 449 |
} |
|---|
| 450 |
|
|---|
| 451 |
$template->assign_vars(array( |
|---|
| 452 |
'PAGINATION' => $pagination, |
|---|
| 453 |
'PAGE_NUMBER' => sprintf($lang['page_of'], ( floor( $start / $config['posts_per_page'] ) + 1 ), ceil( $total_polls / $config['posts_per_page'] )), |
|---|
| 454 |
|
|---|
| 455 |
'L_GOTO_PAGE' => $lang['goto_page']) |
|---|
| 456 |
); |
|---|
| 457 |
|
|---|
| 458 |
|
|---|
| 459 |
// |
|---|
| 460 |
$template->display('pollbody'); |
|---|
| 461 |
include('./page_footer_admin.'.$phpEx); |
|---|
| 462 |
} |
|---|
| 463 |
|
|---|
| 464 |
?> |
|---|