Beispiel #1
0
        echo "Only numbers in the value field";
        exit;
    }
}
if ($_POST["var"] && $_POST["value"]) {
    $db->query($sql, array($my_id, $var, $value));
}
if ($xml == 1) {
    switch ($from) {
        case "mark.php":
            echo "(function() { updateCell('{$my_id}_{$var}', '{$value}');})();";
            break;
        case "user.php":
            $sql = sprintf("SELECT sum(value) total, sum(value) / (to_days(%s) - to_days(%s)) ave from track t where user_id = {$my_id} and var = \"{$var}\" group by var;", get_cz("NOW()"), get_cz("added"));
            $vals = $db->getRow($sql);
            $sql = sprintf("SELECT sum(value) today from track where user_id = {$my_id} and var = \"{$var}\" and to_days(%s) - to_days(%s) = 0 group by var;", get_cz("NOW()"), get_cz("added"));
            $today = $db->getRow($sql);
            if ($vals) {
                if ($value == $vals["total"]) {
                    // new variable
                    echo "(function() { var url = window.location.pathname; setTimeout('window.location = \"'+ url + '\"', 200); function refresh() { window.location = url; } })();";
                } else {
                    $ave = sprintf("%.2f", $vals["ave"]);
                    echo "(function() { updateCell('{$my_id}_{$var}', '{$vals['total']}', '{$my_id}_{$var}_ave', '{$ave}', '{$my_id}_{$var}_today', '{$today['today']}');})();";
                }
            } else {
                echo "Sorry... Problem fetching result";
            }
            break;
        case "day.php":
            echo ".(function() { updateCell('{$my_id}_{$var}', '{$vals['total']}', '{$my_id}_{$var}_ave', '{$ave}', '{$today}');})();";
Beispiel #2
0
<?php

require_once "trackstat.us.php";
$sql = sprintf("select m.id, mark_name, %s mark_start, %s mark_end, concat_ws('|', vars, measurements) vars, group_concat(username ORDER BY username SEPARATOR ' ') users from marks m LEFT JOIN marks_users mu ON mu.mark_id = m.id LEFT JOIN users u ON u.id = mu.user_id where to_days(%s) >= to_days(%s) AND to_days(%s) <= to_days(%s) group by m.id", get_cz("mark_start"), get_cz("mark_end"), get_cz("NOW()"), get_cz("mark_start"), get_cz("NOW()"), get_cz("mark_end"));
$marks = $db->getAll($sql);
foreach ($marks as $a => $b) {
    $marks[$a]["users"] = split(" ", $b["users"]);
    $marks[$a]["vars"] = preg_split("/\\|/", $b["vars"]);
}
$t->assign_by_ref("marks", $marks);
$t->display("openmarks.tpl");
Beispiel #3
0
<?php

require_once "trackstat.us.php";
require_once "charts.php";
$their_id = mysql_escape_string($_REQUEST["their_id"]);
$var = mysql_escape_string($_REQUEST["var"]);
$sql = 'select unix_timestamp(convert_tz(mark_start, "-0:00", "-4:00")) m_s, to_days(convert_tz(mark_end, "-0:00", "-4:00")) - TO_DAYS(convert_tz(mark_start, "-0:00", "-4:00")) as days, username,var,sum(value) total, date(convert_tz(added, "-0:00", "-4:00")) day from track t LEFT JOIN marks_users mu ON mu.user_id = t.user_id LEFT JOIN users u ON u.id = t.user_id LEFT JOIN marks m ON m.id = mu.mark_id where m.id = ' . $mark . ' and var = "' . $var . '" and added >= mark_start and added <= mark_end group by t.user_id,date(convert_tz(added, "-0:00", "-4:00")), var order by var;';
$sql = sprintf("SELECT date(%s) day, sum(value) as total, to_days(%s) - to_days(%s) t_days, sum(value) total, min(%s) first, max(%s) last from track t where user_id = {$their_id} and var = \"{$var}\" group by var, date(%s);", get_cz("added"), get_cz("NOW()"), get_cz("added"), get_cz("added"), get_cz("added"), get_cz("added"));
$rows = $db->getAll($sql);
$dt = "n/d";
for ($i = 0; $i <= $rows[0]["t_days"] + 1; $i++) {
    if (strtotime($rows[0]["first"]) + ($i - 1) * 86400 <= time()) {
        $dates[] = date("{$dt}", strtotime($rows[0]["first"]) + $i * 86400);
    }
}
foreach ($rows as $row) {
    $day = date($dt, strtotime($row["day"]));
    $vars[$var][$day] = $row["total"];
}
$i = 0;
$data[0][0] = "";
foreach ($vars as $var => $val) {
    $data[++$i][0] = $var;
    foreach ($dates as $day) {
        $total = $val[$day] ? $val[$day] : 0;
        if ($val[$day]) {
            $data[0][] = $day;
            $data[$i][] = $total;
        }
    }
}
Beispiel #4
0
if (!$their_id) {
    $t->assign("user", $user);
    $t->display("no_user.tpl");
    exit;
}
// should I change the schema to be start and length?
#$ave = sprintf("TO_DAYS(%s) - TO_DAYS(%s)", get_cz("mark_end"), get_cz("mark_start"));
if ($their_id != $my_id) {
    $extra = "and hidden <> 1";
} else {
    $extra = "";
}
$sql = sprintf("SELECT var, sum(value) as total, to_days(%s) - to_days(%s) + 1 t_days, sum(value) / (to_days(%s) - to_days(%s) + 1) ave, min(%s) first, max(%s) last from track t where user_id = {$their_id} {$extra} group by var;", get_cz("NOW()"), get_cz("min(added)"), get_cz("NOW()"), get_cz("min(added)"), get_cz("added"), get_cz("added"));
$info = $db->getAll($sql);
$cn = get_cz("NOW()");
$cz = get_cz("added");
$sql = "SELECT to_days({$cn}) - to_days(min({$cz})) days from track t where user_id = {$their_id} group by user_id;";
$length = $db->getOne($sql);
if ($start + ($i - 1) * 86400 <= time()) {
}
$sql = "SELECT var, sum(value) total, to_days({$cn}) - to_days({$cz}) ago from track t where user_id = {$their_id} {$extra} group by var, date({$cz}) ORDER BY var;";
//var_dump($db->getAll($sql));
foreach ($db->getAll($sql) as $row) {
    if ($row["ago"] == 0) {
        $today[$row["var"]] = $row["total"];
    }
    $hold[$row["var"]][$row["ago"]] = $row["total"];
    $maxes[$row["var"]] = $maxes[$row["var"]] < $row["total"] ? $row["total"] : $maxes[$row["var"]];
}
foreach ($hold as $var => $row) {
    for ($i = $length; $i >= 0; $i--) {
Beispiel #5
0
             $mark_left = "{$mark_left} Minute" . ($mark_left == 1 ? "" : "s") . " left";
         }
     } else {
         $mark_left = "This contest is closed";
         $days = $mark_total;
     }
 }
 foreach ($mark_info as $row) {
     $uvars[$row["user_id"]]["username"] = $row["username"];
     $mvars[$row["user_id"]]["username"] = $row["username"];
     $sql = "Select var, sum(value) total from track where user_id = {$row['user_id']} and (var = '" . join($vars, "' OR var = '") . "') AND " . get_cz("added") . " <= '{$row['m_e']}' and " . get_cz("added") . " >= '{$row['m_s']}' group by var;";
     foreach ($db->getAll($sql) as $rw) {
         $uvars[$row["user_id"]][$rw["var"]]["total"] = $rw["total"];
         $uvars[$row["user_id"]][$rw["var"]]["ave"] = sprintf("%0.2f", $rw["total"] / $days);
     }
     $sql = "Select var, value from track where user_id = {$row['user_id']} and (var = '" . join($measurements, "' OR var = '") . "') AND " . get_cz("added") . " <= '{$row['m_e']}' and " . get_cz("added") . " >= '{$row['m_s']}' order by var, added;";
     foreach ($db->getAll($sql) as $mw) {
         if (!$mvars[$row["user_id"]][$mw["var"]]["min"]) {
             $mvars[$row["user_id"]][$mw["var"]]["min"] = $mw["value"];
         }
         $mvars[$row["user_id"]][$mw["var"]]["diff"] = sprintf("%0.2f", $mvars[$row["user_id"]][$mw["var"]]["min"] - $mw["value"]);
     }
 }
 $t->assign("title", "Marks - fun for all");
 $t->assign_by_ref("mark_name", $mark_name);
 $t->assign_by_ref("mark_left", $mark_left);
 $t->assign_by_ref("mark_total", $mark_total);
 $t->assign_by_ref("days", $days);
 $t->assign_by_ref("uvars", $uvars);
 $t->assign_by_ref("vars", $vars);
 $t->assign_by_ref("mvars", $mvars);
Beispiel #6
0
<?php

require_once "trackstat.us.php";
$id = $_REQUEST["id"];
if ($id) {
    $sql = "SELECT id, var, value, hidden, unix_timestamp(" . get_cz("added") . ") added FROM track where id = ? and user_id = ?;";
    $stat = $db->getRow($sql, array($_REQUEST["id"], $my_id));
    $t->assign("stat", $stat);
} else {
    $t->assign("error", "Sorry, no id supplied");
}
$t->display("edit_stat.tpl");
Beispiel #7
0
<?php

require_once "trackstat.us.php";
$id = $_REQUEST["id"];
if ($id) {
    $sql = "SELECT id, user_id, var, value, hidden, added FROM track where id = ? and user_id = ?;";
    $stat = $db->getRow($sql, array($_REQUEST["id"], $my_id));
    if ($stat["user_id"] == $my_id) {
        $sql = "UPDATE track set var=?, value=?, hidden=?, added=? where id=?";
        $hidden = $_POST["hidden"] ? $_POST["hidden"] : 0;
        $ad = $_POST["added"];
        $hour = ($ad["Time_Meridian"] == "pm" and $ad["Time_Hour"] != 12) ? $ad["Time_Hour"] + 12 : $ad["Time_Hour"];
        $added = "'{$ad['Date_Year']}-{$ad['Date_Month']}-{$ad['Date_Day']} {$hour}:{$ad['Time_Minute']}:00'";
        $added = $db->getOne("SELECT " . get_cz($added, 1));
        if ($added != "NULL") {
            $db->query($sql, array($_POST["var"], $_POST["value"], $hidden, $added, $_POST["id"]));
            $t->assign("success", 1);
        } else {
            $errors[] = "Invalid date.";
            $t->assign("errors", $errors);
        }
    } else {
        $errors[] = "Sorry, you can not edit that stat, It isn't yours.";
        $t->assign("errors", $errors);
    }
} else {
    $errors[] = "No id supplied";
    $t->assign("errors", $errors);
}
$t->assign("id", $id);
$t->assign("var", $stat["var"]);