} //vd($_POST); if (isset($_POST["boulder"])) { $postdata = $_POST; $postdata["user"] = $userdata->username; $postdata["sector"] = $userdata->sector; //$postdata["ascent"]=$postdata["top"]; //$postdata["datetime"]=date('Y-m-d h:i:s'); //if ($client!=$postdata["user"]){ // die("Error: security."); //} if (!is_numeric($postdata["boulder"]) or !is_numeric($postdata["ascent"])) { echo "<span style='color:red;'>" . _("<b>Error</b>: Problem, register again!") . "</span>"; die; } $bould = get_boulder($postdata["sector"], $postdata["boulder"]); $postdata["boulder_letter"] = $bould["letter"]; $attempt = new data("attempts"); //CREATE a fresh new object (table=users structure without data when second argument is null) foreach ($postdata as $key => $value) { $attempt->{$key} = $value; } //vd($attempt); //die; //$checkdup_target_object=$attempt->target_object; $checkdup_datetime = $attempt->datetime; $checkdup_athlete = $attempt->athlete; $checkdup_sector = $attempt->sector; $checkdup = new data("attempts", "filter:athlete='{$checkdup_athlete}' and datetime='{$checkdup_datetime}'"); if (isset($checkdup->{0}->id)) { echo "<span style='color:red;'>" . _("<b>Error</b>: processing your request, duplicated.") . "</span>";
function get_rank($category, $start = false, $qty = false) { //$athletes = new data("athletes","filter:category='$category' and active='1'",false); //SELECT * FROM ".DBIntrd::$table." WHERE ".$filter if ($category == "all") { $athletes = new data("athletes", "custom:\n\t\t\tSELECT athletes.name,athletes.id,athletes.category,athletes.gender FROM athletes WHERE active=1\n\t\t\t", false); } else { $athletes = new data("athletes", "custom:\n\t\t\tSELECT athletes.name,athletes.id,athletes.category,athletes.gender FROM athletes WHERE active=1 and category='{$category}'\n\t\t\t", false); } $total = count((array) $athletes); if ($start > $total) { $start = 0; } //echo $start; /*$count_flash = new data("attempts","custom: SELECT athlete,count(ascent) FROM attempts WHERE ascent=1 GROUP BY athlete ",false); $count_tops = new data("attempts","custom: SELECT athlete,count(ascent) FROM attempts WHERE ascent=0 GROUP BY athlete ",false);*/ foreach ($athletes as $key => $athlete) { //vd($athlete); //die; $athlete_name = $athlete->name; $athlete_id = $athlete->id; $athlete_cat = $athlete->category; $score[$athlete_name]["id"] = $athlete_id; $score[$athlete_name]["category"] = $athlete_cat; $score[$athlete_name]["gender"] = $athlete->gender; //vd($athelete_name); //die; $attempts = new data("attempts", "filter:athlete='{$athlete_name}' and ascent=0", false); $score[$athlete_name]["attempts"] = count((array) $attempts); $ascents = new data("attempts", "filter:athlete='{$athlete_name}' and ascent=1", false); $score[$athlete_name]["tops"] = count((array) $ascents); $sum = 0; foreach ($ascents as $ascent) { $value = get_boulder($ascent->sector, $ascent->boulder)["value_top"]; $sum = $sum + $value; } $score[$athlete_name]["tops_sum"] = $sum; $flashs = new data("attempts", "filter:athlete='{$athlete_name}' and ascent=2", false); $score[$athlete_name]["flashs"] = count((array) $flashs); $sum = 0; foreach ($flashs as $flash) { $value = get_boulder($flash->sector, $flash->boulder)["value_flash"]; $sum = $sum + $value; } $score[$athlete_name]["flashs_sum"] = $sum; $score[$athlete_name]["total"] = $score[$athlete_name]["flashs_sum"] + $score[$athlete_name]["tops_sum"]; } array_sort_by_column($score, "total", SORT_DESC); //vd($score); //die; //} $score = array_slice($score, $start, $qty); return $score; }