Esempio n. 1
0
function dob_elect_display_mine($post_id, $vm_type, $vm_label, $myval = '', $user_id)
{
    /*{{{*/
    ob_start();
    //session_unset();	// $_SESSION = array();
    $_SESSION['user_id'] = $user_id;
    $_SESSION['post_id'] = $post_id;
    $_SESSION['secret'] = $secret = base64_encode(openssl_random_pseudo_bytes(20));
    if ($vm_type == 'plural') {
        // normalize plural value
        if (is_null($myval) || $myval === '') {
            $myvals = array();
        } else {
            if ($myval <= 1) {
                $myvals = array($myval);
            } else {
                $myvals = array();
                $vals = str_split(strrev(base_convert($myval, 10, 2)));
                //$myval = array_keys(array_filter($vals, function($v){return $v=='1';}));
                foreach ($vals as $k => $v) {
                    if ($v == '1') {
                        $myvals[] = $k + 1;
                    }
                }
            }
        }
    }
    $label_secret = '보안코드';
    //__('Statistics', DOBslug);
    $label_remember = '암호화된 DB에서 직접 투표확인을 원하시면 이 값을 기억해 주세요.';
    //__('Statistics', DOBslug);
    $html_plural_inputs = $vm_type == 'plural' ? '<input type="hidden" name="dob_form_val" value="' . $myval . '">' : '';
    // display area
    echo <<<HTML
\t\t<div class="panel">
\t\t<table>
\t\t\t<form id="formDob" method="post">
\t\t\t<input type="hidden" name="dob_form_type" value="{$vm_type}">
\t\t\t<input type="hidden" name="dob_form_cart" value="0">
\t\t\t<input type="hidden" name="dob_form_old_val" value="{$myval}">
      {$html_plural_inputs}
\t\t\t<!--tr><td>
\t\t\t\t{$label_secret} : <input type="text" name="dob_elect_secret" value="{$secret}" style="width:300px" READONLY>
\t\t\t\t<br><b>{$label_remember}</b>
\t\t\t</td></tr-->
\t\t\t<tr><td id="tdVote">
HTML;
    wp_nonce_field('dob_form_nonce_' . $vm_type, 'dob_form_nonce');
    foreach ($vm_label as $val => $label) {
        $html_input = '';
        if ($vm_type == 'plural') {
            $control = in_array($val, $myvals) ? 'CHECKED' : ($myval === 0 || $myval === -1 ? 'DISABLED' : '');
            $exp = $val < 1 ? $val : 1 << $val - 1;
            $html_input = "<input type='checkbox' data-idx='{$val}' value='{$exp}' {$control} style='margin-left:9px; margin-right:0px;' >";
        } else {
            $checked = $val === $myval ? 'CHECKED' : '';
            $html_input = "<input type='radio' name='dob_form_val' value='{$val}' {$checked}>";
        }
        echo " <label style='margin-bottom:0px; font-size:1.1em;'>{$html_input}{$label}</label> ";
    }
    $html_submit = '';
    if ($user_id) {
        $html_submit = dob_common_get_message($post_id, $user_id, 'elect');
        // vote_post_latest timestamp
        $label_fast = '바로투표';
        //__('Vote', DOBslug);
        $label_cart = '투표바구니';
        //__('Vote', DOBslug);
        $html_submit .= " <input id='btn_fast' type='button' value='{$label_fast}' class='btn btn-success btn-sm' >";
        $html_submit .= " <input id='btn_cart' type='button' value='{$label_cart}' class='btn btn-warning btn-sm' >";
    }
    echo <<<HTML
\t\t\t</td></tr>
\t\t\t<tr><td style="text-align:right;">{$html_submit}</td></tr>
\t\t\t</form>
\t\t</table>
\t\t</div>
HTML;
    $ret = ob_get_contents();
    ob_end_clean();
    return $ret;
}
Esempio n. 2
0
function dob_vote_display_mine($post_id, $vm_type, $vm_legend, $myval = '', $user_id)
{
    /*{{{*/
    ob_start();
    //session_unset();	// $_SESSION = array();
    $LOGIN_IP = empty($_SESSION['LOGIN_IP']) ? '' : $_SESSION['LOGIN_IP'];
    $_SESSION['user_id'] = $user_id;
    $_SESSION['post_id'] = $post_id;
    $_SESSION['secret'] = $secret = base64_encode(openssl_random_pseudo_bytes(20));
    if ($vm_type == 'plural') {
        // normalize plural value
        if (is_null($myval) || $myval === '') {
            $myvals = array();
        } else {
            if ($myval <= 1) {
                $myvals = array($myval);
            } else {
                $myvals = array();
                $vals = str_split(strrev(base_convert($myval, 10, 2)));
                //$myval = array_keys(array_filter($vals, function($v){return $v=='1';}));
                foreach ($vals as $k => $v) {
                    if ($v == '1') {
                        $myvals[] = $k + 1;
                    }
                }
            }
        }
    }
    $label_secret = '보안코드';
    //__('Statistics', DOBslug);
    $label_remember = '암호화된 DB에서 직접 투표확인을 원하시면 이 값을 기억해 주세요.';
    //__('Statistics', DOBslug);
    $html_plural_inputs = $vm_type == 'plural' ? '<input type="hidden" name="dob_form_val" value="' . $myval . '">' : '';
    // display area
    echo <<<HTML
\t\t<div class="panel">
\t\t<table>
\t\t\t<form id="formDob" method="post">
\t\t\t<input type="hidden" name="dob_form_type" value="{$vm_type}">
\t\t\t<input type="hidden" name="dob_form_cart" value="0">
\t\t\t<input type="hidden" name="dob_form_old_val" value="{$myval}">
      {$html_plural_inputs}
\t\t\t<!--tr><td>
\t\t\t\t{$label_secret} : <input type="text" name="dob_vote_secret" value="{$secret}" style="width:300px" READONLY>
\t\t\t\t<br><b>{$label_remember}</b>
\t\t\t</td></tr-->
\t\t\t<tr><td id="tdVote"><div class="well">
HTML;
    wp_nonce_field('dob_form_nonce_' . $vm_type, 'dob_form_nonce');
    foreach ($vm_legend as $val => $label) {
        $html_input = '';
        if ($vm_type == 'plural') {
            $control = in_array($val, $myvals) ? 'CHECKED' : ($myval === 0 || $myval === -1 ? 'DISABLED' : '');
            $exp = $val < 1 ? $val : 1 << $val - 1;
            $html_input = "<input type='checkbox' data-idx='{$val}' value='{$exp}' {$control}>";
        } else {
            $checked = $val === $myval ? 'CHECKED' : '';
            $html_input = "<input type='radio' name='dob_form_val' value='{$val}' {$checked}>";
        }
        echo " <label class='radio-inline checkbox-inline'>{$html_input}{$label}</label> ";
    }
    $html_submit = empty($user_id) ? $label_login : dob_common_get_message($post_id, $user_id, 'offer');
    // vote_post_latest timestamp
    if ($LOGIN_IP == dob_get_real_ip()) {
        $label_fast = '바로투표';
        //__('Vote', DOBslug);
        $label_cart = '투표바구니';
        //__('Vote', DOBslug);
        $html_submit .= " <input id='btn_fast' type='button' value='{$label_fast}' class='btn btn-success btn-sm' >";
        $html_submit .= " <input id='btn_cart' type='button' value='{$label_cart}' class='btn btn-warning btn-sm' >";
    } else {
        $label_iperr_relogin = '******';
        //__('You passed 1-hours after login, or Your network was Changed. Please Login AGAIN.', DOBslug);
        $html_submit .= '<br>' . $label_iperr_relogin;
    }
    echo <<<HTML
\t\t\t</div></td></tr>
\t\t\t<tr><td nowrap style="text-align:right;">{$html_submit}</td></tr>
\t\t\t</form>
\t\t</table>
\t\t</div>
HTML;
    $ret = ob_get_contents();
    ob_end_clean();
    return $ret;
}