示例#1
0
/**
 * Show poll block.
 *
 * @param  boolean			Whether to get the output instead of outputting it directly
 * @param  ?AUTO_LINK		Poll ID (NULL: read from environment)
 * @return ?object			Output (NULL: outputted it already)
 */
function poll_script($ret = false, $param = NULL)
{
    require_lang('polls');
    require_css('polls');
    if (is_null($param)) {
        $param = get_param_integer('param');
    }
    $zone = get_param('zone', get_module_zone('polls'));
    if ($param == -1) {
        $rows = persistant_cache_get('POLL');
        if (is_null($rows)) {
            $rows = $GLOBALS['SITE_DB']->query_select('poll', array('*'), array('is_current' => 1), 'ORDER BY id DESC', 1);
            persistant_cache_set('POLL', $rows);
        }
    } else {
        $rows = $GLOBALS['SITE_DB']->query_select('poll', array('*'), array('id' => $param), '', 1);
    }
    if (has_actual_page_access(NULL, 'cms_polls', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_polls')) {
        $submit_url = build_url(array('page' => 'cms_polls', 'type' => 'ad', 'redirect' => get_self_url(true, false)), get_module_zone('cms_polls'));
    } else {
        $submit_url = new ocp_tempcode();
    }
    if (!array_key_exists(0, $rows)) {
        $content = do_template('BLOCK_NO_ENTRIES', array('_GUID' => 'fdc85bb2e14bdf00830347e52f25cdac', 'HIGH' => true, 'TITLE' => do_lang_tempcode('POLL'), 'MESSAGE' => do_lang_tempcode('NO_ENTRIES'), 'ADD_NAME' => do_lang_tempcode('ADD_POLL'), 'SUBMIT_URL' => $submit_url));
    } else {
        $myrow = $rows[0];
        $ip = get_ip_address();
        // Show the poll normally
        $show_poll_results = get_param_integer('show_poll_results_' . strval($myrow['id']), 0);
        if ($show_poll_results == 0) {
            $content = show_poll(false, $myrow, $zone);
        } else {
            // Voting
            $cast = post_param_integer('cast_' . strval($myrow['id']), -1);
            if ($cast != -1) {
                if (may_vote_in_poll($myrow)) {
                    if (addon_installed('points')) {
                        require_code('points');
                        $_before = point_info(get_member());
                        $before = array_key_exists('points_gained_voting', $_before) ? $_before['points_gained_voting'] : 0;
                        $GLOBALS['FORUM_DRIVER']->set_custom_field(get_member(), 'points_gained_voting', $before + 1);
                    }
                    $GLOBALS['SITE_DB']->query_update('poll', array('votes' . strval($cast) => $myrow['votes' . strval($cast)] + 1), array('id' => $myrow['id']), '', 1);
                    $GLOBALS['SITE_DB']->query_insert('poll_votes', array('v_poll_id' => $myrow['id'], 'v_voter_id' => get_member(), 'v_voter_ip' => $ip, 'v_vote_for' => $cast));
                    $myrow['votes' . strval($cast)]++;
                }
            } else {
                // Viewing the results
                if (may_vote_in_poll($myrow)) {
                    $GLOBALS['SITE_DB']->query_insert('poll_votes', array('v_poll_id' => $myrow['id'], 'v_voter_id' => is_guest() ? NULL : get_member(), 'v_voter_ip' => $ip, 'v_vote_for' => NULL));
                }
            }
            // Show poll, with results
            $content = show_poll(true, $myrow, $zone);
        }
    }
    if ($ret) {
        return $content;
    }
    // Display
    $echo = do_template('STYLED_HTML_WRAP', array('TITLE' => do_lang_tempcode('POLL'), 'FRAME' => true, 'CONTENT' => $content));
    $echo->handle_symbol_preprocessing();
    $echo->evaluate_echo();
    return NULL;
}
示例#2
0
/**
 * @brief display unit resources
 * @global type $tool_content
 * @global type $langUnknownResType
 * @global type $is_editor
 * @param type $info
 * @return type
 */
function show_resource($info)
{
    global $tool_content, $langUnknownResType, $is_editor;
    if ($info->visible == 0 and !$is_editor) {
        return;
    }
    switch ($info->type) {
        case 'doc':
            $tool_content .= show_doc($info->title, $info->comments, $info->id, $info->res_id);
            break;
        case 'text':
            $tool_content .= show_text($info->comments, $info->id, $info->visible);
            break;
        case 'description':
            $tool_content .= show_description($info->title, $info->comments, $info->id, $info->res_id, $info->visible);
            break;
        case 'lp':
            $tool_content .= show_lp($info->title, $info->comments, $info->id, $info->res_id);
            break;
        case 'video':
        case 'videolink':
            $tool_content .= show_video($info->type, $info->title, $info->comments, $info->id, $info->res_id, $info->visible);
            break;
        case 'videolinkcategory':
            $tool_content .= show_videocat($info->type, $info->title, $info->comments, $info->id, $info->res_id, $info->visible);
            break;
        case 'exercise':
            $tool_content .= show_exercise($info->title, $info->comments, $info->id, $info->res_id, $info->visible);
            break;
        case 'work':
            $tool_content .= show_work($info->title, $info->comments, $info->id, $info->res_id, $info->visible);
            break;
        case 'topic':
        case 'forum':
            $tool_content .= show_forum($info->type, $info->title, $info->comments, $info->id, $info->res_id, $info->visible);
            break;
        case 'wiki':
            $tool_content .= show_wiki($info->title, $info->comments, $info->id, $info->res_id, $info->visible);
            break;
        case 'poll':
            $tool_content .= show_poll($info->title, $info->comments, $info->id, $info->res_id, $info->visible);
            break;
        case 'link':
            $tool_content .= show_link($info->title, $info->comments, $info->id, $info->res_id, $info->visible);
            break;
        case 'linkcategory':
            $tool_content .= show_linkcat($info->title, $info->comments, $info->id, $info->res_id, $info->visible);
            break;
        case 'ebook':
            $tool_content .= show_ebook($info->title, $info->comments, $info->id, $info->res_id, $info->visible);
            break;
        case 'section':
            $tool_content .= show_ebook_section($info->title, $info->comments, $info->id, $info->res_id, $info->visible);
            break;
        case 'subsection':
            $tool_content .= show_ebook_subsection($info->title, $info->comments, $info->id, $info->res_id, $info->visible);
            break;
        default:
            $tool_content .= $langUnknownResType;
    }
}
示例#3
0
    if ($LOGIN_LEVEL >= AUTH_DEVEL) {
        $op = 'l';
    } else {
        $op = 'c';
    }
}
if ($poll == 0 && $op != 'u' && $op != 'n') {
    $poll = get_recent_poll();
}
// Do it!
switch ($op) {
    case 'c':
        // Show a poll
        html_header("Poll #{$poll}");
        print "<h1>Poll #{$poll}</h1>\n";
        show_poll($poll);
        html_footer();
        break;
    case 'l':
        // List all polls
        html_header("Polls");
        if ($LOGIN_LEVEL > AUTH_USER) {
            // Show all polls and allow poll creation...
            $result = db_query("SELECT * FROM poll ORDER BY id DESC");
            html_start_links(1);
            html_link("Add New Poll", "{$PHP_SELF}?n");
            html_end_links(1);
        } else {
            // Only show published polls...
            $result = db_query("SELECT * FROM poll WHERE is_published = 1 " . "ORDER BY id DESC");
        }