function compo_options() { $action = isset($_REQUEST["action"]) ? $_REQUEST["action"] : ""; if ($action == 'submit') { foreach ($_REQUEST as $k => $v) { if (strpos($k, "compo-") !== 0) { continue; } $prev = get_option($k); $v = str_replace(" ", "", $v); update_option($k, $v, "", "no"); } echo '<div id="message" class="updated fade"><p>Options Updated</p></div>'; } echo "<div class='wrap'>"; echo "<h2>Compo Options</h2>"; $a = str_replace('%7E', '~', $_SERVER['REQUEST_URI']); echo "<form method='post' action='{$a}'>"; echo "<input type='hidden' name='action' value='submit'>"; echo "<table>"; echo "<tr><th><th>State<th>Categories (e.g. innovation,fun,production,overall)"; $cats = get_categories(); foreach ($cats as $e) { echo "<tr>"; echo "<th>{$e->name}"; echo "<td>"; $k = "compo-{$e->term_id}-state"; $v = get_option($k); compo_select($k, array("" => "", "active" => "Active", "rate" => "Rate", "results" => "Results"), $v); echo "<td>"; $k = "compo-{$e->term_id}-cats"; $v = get_option($k); echo "<input type='text' name='{$k}' value='" . htmlentities($v) . "' size=80>"; } echo "</table>"; echo "<input type='submit' value='Update Options'>"; echo "</form>"; echo "</div>"; }
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>"; }