Ejemplo n.º 1
0
function compo_rate_rate($cid, $uid)
{
    global $compo;
    $cat = get_category($cid);
    $topurl = get_bloginfo("url");
    $k = "compo-{$cid}-cats";
    $cats = get_option($k);
    $action = isset($_REQUEST["compo_action"]) ? $_REQUEST["compo_action"] : "default";
    $user = wp_get_current_user();
    if ($user->ID == $uid) {
        //         echo "<p>You don't get to rate your own entry, silly!</p>";
        compo_trophy($uid);
        return;
    }
    if ($action == "submit") {
        $e = array();
        foreach (explode(",", $cats) as $k) {
            $v = $_REQUEST[$k];
            if (strlen($v)) {
                $e[$k] = max(1, min(5, intval($v)));
            }
        }
        compo_query("delete from {$compo["rate.table"]} where cid = ? and from_uid = ? and to_uid = ?", array($cid, $user->ID, $uid));
        compo_query("insert into {$compo["rate.table"]} (cid,from_uid,to_uid,data,comment) values (?,?,?,?,?)", array($cid, $user->ID, $uid, serialize($e), $_REQUEST["comment"]));
        compo_calc($cid, $uid);
        //         return;
        //         echo "<p><b>Ratings saved.</b></p>";
        header("Location: {$topurl}/category/{$cat->slug}/");
        die;
    }
    echo "<h3>Rate this entry</h3>";
    echo "<p>Rate on a 1-5 scale where 1 is lowest and 5 is highest.  Mark n/a if the category is not applicable to the entry, or you are not able to rate that category.</p>";
    echo "<form method=post action='{$_SERVER['REQUEST_URI']}'>";
    echo "<input type='hidden' name='compo_action' value='submit'>";
    echo "<table>";
    $r = compo_query("select * from {$compo["rate.table"]} where cid = ? and from_uid = ? and to_uid = ?", array($cid, $user->ID, $uid));
    $ee = $r[0];
    //     print_r($ee);
    $e = count($r) ? unserialize($ee["data"]) : array();
    foreach (explode(",", $cats) as $k) {
        echo "<tr>";
        echo "<th>" . ucfirst($k);
        echo "<td>";
        $v = isset($e[$k]) ? $e[$k] : "";
        compo_select($k, array("" => "n/a", "5" => "5", "4" => "4", "3" => "3", "2" => "2", "1" => "1"), $v);
    }
    echo "</table>";
    echo "<p>Comments:<br><textarea cols=50 rows=5 name='comment'>" . htmlentities($ee["comment"]) . "</textarea></p>";
    echo "<input type='submit' value='Save'>";
    echo "</form>";
}
Ejemplo 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)));
    }
}