示例#1
0
 function get_elect_html_stat($post_id, $stat)
 {
     /*{{{*/
     $dob_elect_cmb_vote = get_post_meta($post_id, 'dob_elect_cmb_vote', true);
     $vm_begin = empty($dob_elect_cmb_vote['begin']) ? '' : $dob_elect_cmb_vote['begin'];
     $vm_end = empty($dob_elect_cmb_vote['end']) ? '' : $dob_elect_cmb_vote['end'];
     return dob_elect_html_stat($stat['nDirect'], $stat['nTotal'], $vm_begin, $vm_end, true);
 }
示例#2
0
function dob_elect_contents($post_id, $bEcho = false)
{
    #echo '<pre>';
    global $wpdb;
    $dob_elect_cmb_vote = get_post_meta($post_id, 'dob_elect_cmb_vote', true);
    $vm_type = empty($dob_elect_cmb_vote['type']) ? 'updown' : $dob_elect_cmb_vote['type'];
    $vm_data = empty($dob_elect_cmb_vote['data']) ? array() : $dob_elect_cmb_vote['data'];
    $vm_begin = empty($dob_elect_cmb_vote['begin']) ? '' : $dob_elect_cmb_vote['begin'];
    $vm_end = empty($dob_elect_cmb_vote['end']) ? '' : $dob_elect_cmb_vote['end'];
    $user_id = get_current_user_id();
    $LOGIN_IP = empty($_SESSION['LOGIN_IP']) ? '' : $_SESSION['LOGIN_IP'];
    $bVote = false;
    if (is_single() && $user_id) {
        $debug = '';
        if (!empty($_POST) && $LOGIN_IP == dob_get_real_ip()) {
            $bVote = true;
            if ((int) $_POST['dob_form_cart']) {
                $debug = dob_common_cart($user_id, $post_id, 'elect');
            } else {
                $debug = dob_common_update($user_id, $post_id, 'elect');
            }
        }
        if ($debug) {
            echo "<pre>{$debug}</pre>";
        }
    }
    // load CACHE
    $ts_struct = $ts_all = $ts_stat = '';
    $ts_post = get_the_modified_time('Y-m-d H:i:s');
    $cached_struct = dob_common_cache(-1, 'all', false, $ts_struct);
    $cached_all = dob_common_cache($post_id, 'all', false, $ts_all);
    $cached_stat_json = dob_common_cache($post_id, 'stat', false, $ts_stat, false);
    $ttids = $elect_latest = $result_stat = $stat = null;
    if (is_array($cached_all)) {
        extract($cached_all);
    }
    $nTotal = null;
    $nDirect = null;
    if (!empty($stat)) {
        extract($stat);
    }
    // ttids: 신규, 포스트변경, 계층변경
    $bTtids = false;
    if ($ttids === null || $ts_all < $ts_post || $ts_all < $ts_struct) {
        $ttids = dob_common_get_selected_hierarchy_leaf_ttids($post_id);
        $bTtids = true;
    }
    // nTotal: 신규, 포스트변경, 계층변경
    if ($nTotal === null || $ts_all < $ts_post || $ts_all < $ts_struct) {
        $nTotal = dob_common_get_users_count($ttids);
        // get all user count
    }
    // elect_latest, stat_detail: 신규, 투표, 포스트변경, 계층변경
    $bLatest = false;
    if ($elect_latest === null || $bVote || $ts_all < $ts_post || $ts_all < $ts_struct) {
        $elect_latest = dob_common_get_latest_by_ttids($post_id, $ttids, 'elect');
        // user_id => rows	// for login_name
        $nDirect = is_array($elect_latest) ? count($elect_latest) : 0;
        $bLatest = true;
    }
    // build final vote results.
    $myinfo = $user_id ? dob_common_get_user_info($user_id) : null;
    $myval = isset($elect_latest[$user_id]) ? (int) $elect_latest[$user_id]['value'] : '';
    #print_r($elect_latest);
    // Cache STAT, 통계: 신규, 실제 통계값 변경
    $bStat = false;
    $stat = ['nDirect' => $nDirect, 'nTotal' => $nTotal];
    $stat_json = json_encode($stat, JSON_UNESCAPED_UNICODE);
    if (empty($cached_stat_json) || $cached_stat_json != $stat_json) {
        $ts_now = date('Y-m-d H:i:s');
        dob_common_cache($post_id, 'stat', $stat_json, $ts_now, false);
        $bStat = true;
    }
    $bResult = false;
    if (strtotime($vm_end) < time() && ($result_stat === null || $bTtids || $bLatest || $bStat)) {
        // AFTER voting period
        $result_stat = array();
        foreach ($elect_latest as $uid => $v) {
            dob_elect_accum_stat($result_stat, $vm_type, $v['value'], 1);
        }
        $bResult = true;
    }
    if ($bTtids || $bLatest || $bStat || $bResult) {
        // Cache Results, 결과: 신규, 포스트변경, 계층변경
        $data = compact('ttids', 'elect_latest', 'result_stat', 'stat');
        dob_common_cache($post_id, 'all', $data);
    }
    ## build HTML /*{{{*/
    //$label_title		= '균형 투표';	//__('Balance Voting', DOBslug);
    $label_result = '투표결과';
    //__('My Vote', DOBslug);
    $label_before = '시작전';
    //__('Statistics', DOBslug);
    $label_ing = '진행중';
    //__('Statistics', DOBslug);
    $label_after = '종료됨';
    //__('Statistics', DOBslug);
    $label_chart = '결과 차트';
    //__('Direct voter', DOBslug);
    $label_my = '내 투표';
    //__('My Vote', DOBslug);
    $label_history = '기록';
    //__('My Vote', DOBslug);
    $label_login = '******';
    //__('Please Login', DOBslug);
    /*}}}*/
    $html_timer = $html_chart = $html_form = $html_history = '';
    if (is_single()) {
        $vm_label = $vm_type == 'updown' ? array(-1 => '반대', 0 => '기권') : array(-1 => '모두반대', 0 => '기권');
        if ($vm_type == 'updown') {
            $vm_label[1] = '찬성';
        } else {
            // choice, plural
            foreach ($vm_data as $k => $v) {
                $vm_label[$k + 1] = $v;
            }
        }
        /*}}}*/
        $ts = time();
        $html_timer = dob_elect_html_timer($ts);
        if ($ts < strtotime($vm_begin)) {
            // BEFORE
            $label_result .= ' : ' . $label_before;
        } elseif (strtotime($vm_begin) < $ts && $ts < strtotime($vm_end)) {
            // VOTING /*{{{*/
            $label_result .= ' : ' . $label_ing;
            $content_form = "<a href='" . wp_login_url($_SERVER['REQUEST_URI']) . "' style='color:red; font-weight:bold'>{$label_login}</a>";
            if ($user_id) {
                if (is_null($ttids)) {
                    $content_form = '선거대상 계층이 지정되지 않았습니다.';
                    //__('Election Hierarchy does not selected.', DOBslug);
                } elseif (empty($ttids) && empty($myinfo->term_taxonomy_id) || is_array($ttids) && !empty($ttids) && !in_array($myinfo->term_taxonomy_id, $ttids)) {
                    $label_restrict = '선거대상 계층이 아닙니다.';
                    //__('Your hierarchy is not available in this voting.', DOBslug);
                    $content_form = "<span style='color:red; font-weight:bold'>{$label_restrict}</span>";
                } elseif (isset($_SESSION['LOGIN_IP']) && $_SESSION['LOGIN_IP'] == dob_get_real_ip()) {
                    $content_form = dob_elect_display_mine($post_id, $vm_type, $vm_label, $myval, $user_id);
                } else {
                    $content_form = '로그인 이후 1시간이 지났거나, 네트워크가 변경되었으니, 다시 로그인해 주세요<br>투표시에는 네트워크(WIFI,LTE,3G)를 변경하지 마세요.';
                    //__('You passed 1-hours after login, or Your network was Changed. Please Login AGAIN.', DOBslug);
                }
            }
            $html_form = <<<HTML
    <div class="panel panel-default">
      <div class="panel-heading" data-toggle="collapse" data-target="#dob_elect_my">
        <span class="panel-title">{$label_my}</span>
      </div>
      <div id="dob_elect_my" class="panel-collapse collapse in">
\t\t\t\t{$content_form} 
      </div>
    </div>
HTML;
            /*}}}*/
        } else {
            // AFTER /*{{{*/
            $label_result .= ' : ' . $label_after;
            $content_chart = dob_elect_html_chart($result_stat, $vm_label, $nTotal, $nDirect, $vm_type == 'plural');
            $html_chart = <<<HTML
    <div class="panel panel-default">
      <div class="panel-heading" data-toggle="collapse" data-target="#dob_elect_html_chart">
        <span class="panel-title">{$label_chart}</span>
      </div>
      <div id="dob_elect_html_chart" class="panel-collapse collapse in">
        {$content_chart}
      </div>
    </div>
HTML;
        }
        /*}}}*/
    }
    $html_stat = dob_elect_html_stat($nDirect, $nTotal, $vm_begin, $vm_end, false);
    $dob_elect = <<<HTML
\t{$html_stat}
\t{$html_chart}
\t{$html_form}
\t{$html_history}
HTML;
    if ($bEcho) {
        echo $dob_elect;
    } else {
        return $dob_elect;
    }
}