}
$smarty->assign('pollId', $_REQUEST["pollId"]);
if (isset($_REQUEST["setlast"])) {
    check_ticket('admin-polls');
    $polllib->set_last_poll();
}
if (isset($_REQUEST["closeall"])) {
    check_ticket('admin-polls');
    $polllib->close_all_polls();
}
if (isset($_REQUEST["activeall"])) {
    check_ticket('admin-polls');
    $polllib->active_all_polls();
}
if ($_REQUEST["pollId"]) {
    $info = $polllib->get_poll($_REQUEST["pollId"]);
} else {
    $info = array();
    $info["title"] = '';
    $info["active"] = 'y';
    $info["publishDate"] = $tikilib->now;
}
$smarty->assign('title', $info["title"]);
$smarty->assign('active', $info["active"]);
$smarty->assign('publishDate', $info["publishDate"]);
if (isset($_REQUEST["remove"])) {
    $area = 'delpoll';
    if ($prefs['feature_ticketlib2'] != 'y' or isset($_POST['daconfirm']) and isset($_SESSION["ticket_{$area}"])) {
        key_check($area);
        $polllib->remove_poll($_REQUEST["remove"]);
    } else {
    $_REQUEST['find'] = '';
}
$smarty->assign_by_ref('find', $_REQUEST['find']);
$polls = $polllib->list_active_polls(0, $_REQUEST["maxRecords"], "votes_desc", $_REQUEST['find']);
$pollIds = array();
if (isset($_REQUEST["pollId"])) {
    $pollIds[] = $_REQUEST["pollId"];
} else {
    foreach ($polls["data"] as $pId) {
        $pollIds[] = $pId["pollId"];
    }
}
$poll_info_arr = array();
foreach ($pollIds as $pK => $pId) {
    // iterate each poll
    $poll_info = $polllib->get_poll($pId);
    $poll_info_arr[$pK] = $poll_info;
    $options = $polllib->list_poll_options($pId);
    $temp_max = count($options);
    $total = 0;
    $isNum = true;
    // try to find if it is a numeric poll with a title like +1, -2, 1 point...
    for ($i = 0; $i < $temp_max; $i++) {
        if ($poll_info["votes"] == 0) {
            $percent = 0;
        } else {
            $percent = number_format($options[$i]["votes"] * 100 / $poll_info["votes"], 2);
            $options[$i]["percent"] = $percent;
            if ($isNum) {
                if (preg_match('/^([+-]?[0-9]+).*/', $options[$i]['title'], $matches)) {
                    $total += $options[$i]['votes'] * $matches[1];