Esempio n. 1
0
function compo_show_details($cid, $uid)
{
    global $compo;
    $user = wp_get_current_user();
    $cats = get_option("compo-{$cid}-cats");
    $r = compo_query("select * from {$compo["rate.table"]} where cid = ? and to_uid = ?", array($cid, $uid));
    shuffle($r);
    // don't want who voted for what to be obvious
    echo "<h3>Ratings</h3>";
    echo "<p><table>";
    echo "<tr><th>";
    foreach (explode(",", $cats) as $k) {
        echo "<th>" . ucfirst(substr($k, 0, 3));
    }
    foreach ($r as $e) {
        if ($e["from_uid"] == "0") {
            $totals = $e;
            continue;
        }
        echo "<tr>";
        echo "<th>";
        $tp = "td";
        if ($e["from_uid"] == $user->ID) {
            echo "You";
            $tp = "th";
        }
        $re = unserialize($e["data"]);
        foreach (explode(",", $cats) as $k) {
            $v = isset($re[$k]) ? $re[$k] : "";
            echo "<{$tp} align=center>{$v}";
        }
    }
    $e = $totals;
    echo "<tr><th>";
    $re = unserialize($e["data"]);
    foreach (explode(",", $cats) as $k) {
        $v = isset($re[$k]) ? $re[$k] : "";
        $v = compo_number_format($v);
        echo "<th align=center>{$v}";
    }
    echo "</table></p>";
}
Esempio n. 2
0
function compo_results($cid)
{
    global $compo;
    $cid = intval($cid);
    $cat = get_category($cid);
    $state = get_option("compo-{$cid}-state");
    if ($state == "") {
        return;
    }
    $users = compo_get_finalists($cid);
    $topurl = get_bloginfo("url");
    $cats = get_option("compo-{$cid}-cats");
    /*    $user = wp_get_current_user();
        print_r($user);*/
    $user = wp_get_current_user();
    if (isset($_REQUEST["compo_recalc"]) && $user->user_level == 10) {
        foreach ($users as $uid) {
            compo_calc($cid, $uid);
        }
        echo "<p>Recalculated results...</p>";
    }
    if ($state == "active") {
        $user = wp_get_current_user();
        echo "<h3>Compo Active</h3>";
        /*        echo "<p>";
                echo "Your entry wi
                foreach (explode(",",$cats) as $k) { echo ucfirst($k)." "; }
                echo "</p>";*/
        echo "<p>";
        foreach ($users as $final_id) {
            $auth = get_userdata($final_id);
            echo "<a href='{$topurl}/?category_name={$cat->slug}&author_name={$auth->user_nicename}'>{$auth->display_name}</a> ";
        }
        echo "</p>";
    } elseif ($state == "rate") {
        $r = compo_query("select to_uid post_author,count(*) cnt from {$compo["rate.table"]} where cid = ? and from_uid != 0 and to_uid in (" . implode(",", $users) . ") group by to_uid order by cnt desc", array($cid));
        /*
        // sort by cnt
        $data = array();
        foreach ($users as $final_id) {
            $data[$final_id] = "0|$final_id";
        }
        foreach ($r as $e) {
            $data[$e["post_author"]] = "{$e["cnt"]}|{$e["post_author"]}";
        }
        sort($data);
        */
        // sort by random (but diff rand per user)
        $data = array();
        $user = wp_get_current_user();
        foreach ($users as $final_id) {
            $key = md5("{$user->ID}|{$final_id}");
            $cnt = 0;
            $data[$key] = "{$cnt}|{$final_id}";
        }
        foreach ($r as $e) {
            $final_id = $e["post_author"];
            $cnt = $e["cnt"];
            $key = md5("{$user->ID}|{$final_id}");
            $data[$key] = "{$cnt}|{$final_id}";
        }
        ksort($data);
        $user = wp_get_current_user();
        if (!compo_can_rate($cid, $user->ID)) {
            return;
        }
        echo "<h3>Your Ratings</h3>";
        echo "<p><table>";
        echo "<tr><td><th>C";
        foreach (explode(",", $cats) as $k) {
            echo "<th>" . ucfirst(substr($k, 0, 3));
        }
        //         foreach ($r as $e) {
        $total = 0;
        foreach ($data as $dd) {
            list($cnt, $final_id) = explode("|", $dd);
            echo "<tr>";
            //             $auth = get_userdata($e["post_author"]);
            $auth = get_userdata($final_id);
            echo "<td><a href='{$topurl}/?category_name={$cat->slug}&author_name={$auth->user_nicename}'>{$auth->display_name}</a> ({$cnt})";
            $r = compo_query("select * from {$compo["rate.table"]} where cid = ? and from_uid = ? and to_uid = ?", array($cid, $user->ID, $auth->ID));
            echo "<td>";
            if (strlen($r[0]["comment"])) {
                echo "X";
            }
            $re = count($r) ? unserialize($r[0]["data"]) : array();
            foreach (explode(",", $cats) as $k) {
                $v = isset($re[$k]) ? $re[$k] : "";
                echo "<td align=center>{$v}";
            }
            $total += 1;
            if ($total > 20 && !isset($_REQUEST["compo_results_all"])) {
                break;
            }
        }
        echo "</table></p>";
        if (!isset($_REQUEST["compo_results_all"])) {
            echo "<p><form ><input type='hidden' name='compo_results_all' value='1'><input type='submit' value='Show all Entries'></form></p>";
        }
    } elseif ($state == "results") {
        //         $r = compo_query($sql,array($cid));
        $vdata = array();
        $cdata = array();
        $total = 0;
        foreach ($users as $final_id) {
            $auth = get_userdata($final_id);
            $rr = compo_query("select * from {$compo["rate.table"]} where cid = ? and from_uid = ? and to_uid = ?", array($cid, 0, $auth->ID));
            if (!count($rr)) {
                continue;
            }
            $re = count($rr) ? unserialize($rr[0]["data"]) : array();
            //             $e["auth"] = $auth;
            foreach (explode(",", $cats) as $k) {
                $v = isset($re[$k]) ? $re[$k] : "";
                $v = compo_number_format($v, 2);
                if ($v != "") {
                    $vdata[$k][] = $v;
                    $cdata[$k][] = "{$v}:{$auth->user_nicename}:{$auth->display_name}";
                }
                $e[$k] = $v;
            }
            $total += 1;
            //             $data[] = $e;
        }
        foreach ($cdata as $k => $lst) {
            rsort($cdata[$k]);
        }
        foreach ($vdata as $k => $lst) {
            rsort($vdata[$k]);
        }
        echo "<h3>Final Results</h3>";
        $limit = isset($_REQUEST["compo_limit"]) ? $_REQUEST["compo_limit"] : 0;
        if (!$limit) {
            echo "<p><a href='?compo_limit={$total}'>Show full results</a></p>";
        }
        //         echo "<p><a href='?compo_page=who_voted_prize'>See who did the most voting</a></p>";
        _compo_show_results($cid, $cats, $cdata, $vdata, max(5, min($total, $limit)));
    }
}