예제 #1
0
function bicou_mysql_select($columns = NULL, $table = NULL, $selection = NULL, $selectionArgs = NULL, $order = NULL, $group = NULL, $limit = NULL)
{
    global $table_prefix;
    // Columns
    if ($columns != NULL) {
        $cols = implode(", ", $columns);
    } else {
        $cols = "*";
    }
    // Table
    if ($table != NULL) {
        $tbl = "FROM {$table_prefix}" . $table;
    } else {
        $tbl = "FROM {$table_prefix}crashes";
    }
    // Selection
    if ($selection == NULL) {
        $condition = "1";
    } else {
        $sel = str_replace(array("%", "?"), array("%%", "%s"), $selection);
        $selA = array();
        foreach ($selectionArgs as $s) {
            if (gettype($s) == "integer") {
                $selA[] = "{$s}";
            } else {
                if (gettype($s) == "double") {
                    $selA[] = sprintf("%.5f", 0 + $s);
                } else {
                    if (gettype($s) == "string") {
                        $selA[] = "'" . mysql_real_escape_string($s) . "'";
                    } else {
                        bicou_log("Unhandled SQL type: " . gettype($s) . " with value '{$s}'");
                        $selA[] = mysql_real_escape_string($s);
                    }
                }
            }
        }
        $condition = vsprintf($sel, $selA);
    }
    // Order
    if ($order == NULL) {
        $order = "id DESC";
    }
    // Group
    if ($group != null) {
        $grp = "GROUP BY " . mysql_real_escape_string($group);
    } else {
        $grp = "";
    }
    // Limit
    if ($limit != null) {
        $lmt = "LIMIT " . mysql_real_escape_string($limit);
    } else {
        $lmt = "";
    }
    $sql = "SELECT {$cols} {$tbl} WHERE {$condition} {$grp} ORDER BY {$order} {$lmt}";
    //	echo $sql;
    return $sql;
}
예제 #2
0
 * Copyright 2013 Benoit Duffez
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
include "crashes.php";
include "mysql.php";
$field = $_GET[field] == 'overview' ? "stack_trace" : $_GET[field];
// Display reports
$sql = bicou_mysql_select(array($field), "crashes", "id = ?", array($_GET[id]), null, null, "0, 100");
$res = mysql_query($sql);
if (!$res) {
    bicou_log("Unable to query: {$sql}");
    echo "<p>Server error.</p>\n";
    return;
}
$tab = mysql_fetch_assoc($res);
if ($_GET[field] == 'overview') {
    $tab[$field] = "<ul><li>" . str_replace("<br />", "</li><li>", bicou_stack_trace_overview($tab[$field], null)) . "</li></ul>";
    $tab[$field] = str_replace("<li></li>", "", $tab[$field]);
}
echo '<pre>' . $tab[$field] . '</pre>';
예제 #3
0
//fputs($f, "access on ".date("d/M/Y G:i:s")."\n");
//fclose($f);
ob_start();
// Check _POST
if (count($_POST) == 0) {
    bicou_log("Empty _POST query");
    die;
}
foreach ($_POST as $k => $v) {
    if (array_search(strtolower($k), $values) === FALSE) {
        continue;
    }
    $object[strtolower($k)] = mysql_real_escape_string($v);
}
// Add custom data
$object['added_date'] = time();
$object['status'] = STATE_NEW;
$object['issue_id'] = bicou_issue_id($object['stack_trace'], $object['package_name']);
// Save to DB
$sql = bicou_mysql_insert($object);
$success = mysql_query($sql);
if ($success != TRUE) {
    bicou_log("Unable to save record: " . mysql_error());
    bicou_log("Query was: " . $sql);
}
// Close MySQL
mysql_close($mysql);
//$f = fopen("log", "w+");
//fputs($f, "Output of ".date("d/M/Y G:i:s").":\n".ob_get_clean());
//fclose($f);
echo "Oh, hai!";
예제 #4
0
function display_crashes($status)
{
    global $_GET;
    $columns = array();
    $columns[] = 'MAX(added_date) as last_seen';
    $columns[] = 'COUNT(issue_id) as nb_errors';
    $columns[] = issue_id;
    if (!$_GET['v']) {
        $columns[] = 'MAX(app_version_code) as version_code';
    }
    $columns[] = 'MAX(app_version_name) as version_name';
    $columns[] = 'package_name';
    $columns[] = 'phone_model';
    $columns[] = 'android_version';
    $columns[] = 'stack_trace';
    $sel = "status = ?";
    $selA = array($status);
    // Filter by package
    if (!empty($_GET['package'])) {
        $sel .= " AND package_name LIKE ?";
        $selA[] = $_GET['package'];
    }
    // Filter by app version code
    if (!empty($_GET['v'])) {
        $sel .= " AND app_version_code = ?";
        $selA[] = mysql_real_escape_string($_GET['v']);
    }
    // Search
    if ($_GET[q] != '') {
        $args = explode(" ", $_GET[q]);
        foreach ($args as $arg) {
            if ($arg[0] == "-") {
                $sel .= " AND phone_model NOT LIKE '%?%'";
                $selA[] = substr($arg, 1);
            } else {
                $sel .= " AND phone_model LIKE '%?%'";
                $selA[] = $arg;
            }
        }
    }
    $order = array();
    if ($_GET['v']) {
        $order[] = "nb_errors DESC";
    }
    if ($_GET['start']) {
        $start = $_GET['start'];
    } else {
        $start = 0;
    }
    if (!$_GET['v']) {
        $order[] = "version_code DESC";
    }
    $order[] = "last_seen DESC";
    $tables = "crashes";
    $sql = bicou_mysql_select($columns, $tables, $sel, $selA, implode(", ", $order), "issue_id", "{$start}, 50");
    $res = mysql_query($sql);
    if (!$res) {
        bicou_log("Unable to query: {$sql}");
        echo "<p>Server error: " . mysql_error() . "</p>\n";
        echo "<p>SQL: {$sql}</p>";
        return;
    } else {
        if (mysql_num_rows($res) == 0) {
            echo "<p>No result for this query.</p>\n";
            return;
        }
    }
    echo "<h1>" . status_name($status) . " reports (" . mysql_num_rows($res) . ")</h1>\n";
    if ($_GET[q] != '') {
        echo "<p>Filtered with phone_model matching '{$_GET['q']}'</p>\n";
    }
    $first = 1;
    echo "<table class=\"crashes\">\n";
    while ($tab = mysql_fetch_assoc($res)) {
        // Display table header
        if ($first == 1) {
            echo "<thead>\n<tr><th>&nbsp;</th>\n";
            foreach ($tab as $k => $v) {
                if ($k == "stack_trace") {
                    $k = "exception";
                } else {
                    if ($k == "issue_id") {
                        continue;
                    }
                }
                echo "<th>{$k}</th>\n";
            }
            $first = 0;
            echo "</tr>\n</thead>\n<tbody>\n";
        }
        // Display table contents
        echo "<tr id=\"id_" . $tab['id'] . "\">\n<td><a href=\"" . APP_PACKAGE_URI . "/issue/" . $tab['issue_id'] . "\">VIEW</a></td>\n";
        foreach ($tab as $k => $v) {
            if ($k == "stack_trace") {
                $errors = "<pre><ul><li>" . str_replace("<br />", "</li><li>", bicou_stack_trace_overview($v, $_GET['package'])) . "</li></ul></pre>\n";
                $value = str_replace("<li></li>", "", $errors);
            } else {
                if ($k == "last_seen") {
                    $value = date("d/M/Y G:i:s", $v);
                } else {
                    if ($k == "status") {
                        $value = status_name($tab['status']);
                    } else {
                        if ($k == "version_code") {
                            if ($_GET['v']) {
                                $value = "N/A";
                            } else {
                                $c = array('app_version_code', 'count(app_version_code) as nb');
                                $sl = "issue_id = '?'";
                                $slA = array($tab['issue_id']);
                                $s = bicou_mysql_select($c, "crashes", $sl, $slA, 'nb DESC', 'app_version_code');
                                $r = mysql_query($s);
                                $js = "\$(document).ready(function(){\n" . "\tvar data = [\t";
                                $value = "";
                                while ($t = mysql_fetch_assoc($r)) {
                                    if (strlen($value)) {
                                        $js .= ", ";
                                    }
                                    $js .= "['V: " . $t['app_version_code'] . "', " . $t[nb] . "]";
                                    $value .= '<b title="' . $t[nb] . ' occurrences">' . $t['app_version_code'] . "</b> (" . sprintf("%.1f%%", 100.0 * $t[nb] / $tab[nb_errors]) . ")<br />";
                                }
                                $js .= "\t ];\n" . "\tvar plot_" . $tab['issue_id'] . " = jQuery.jqplot ('chartdiv_" . $tab['issue_id'] . "', [data], \n" . "\t      { \n" . "\t\tseriesDefaults: {\n" . "\t\t      renderer: jQuery.jqplot.PieRenderer, \n" . "\t\t      rendererOptions: {\n" . "\t\t\tshowDataLabels: true\n" . "\t\t      }\n" . "\t\t}, \n" . "\t      }\n" . "\t);\n" . "      });\n";
                                $value .= '<div id="chartdiv_' . $tab['issue_id'] . '" style="height:200px;width:200px; "></div>';
                                $value .= '<script>' . $js . '</script>';
                            }
                        } else {
                            if ($k == "TODO") {
                            } else {
                                if ($k == "issue_id") {
                                    continue;
                                } else {
                                    $value = $v;
                                }
                            }
                        }
                    }
                }
            }
            $style = $k != "stack_trace" ? ' style="text-align: center;"' : "";
            // Display the row
            if (0 && strstr($value, "\n") !== FALSE) {
                $value = "<textarea>{$value}</textarea>";
            }
            echo "<td{$style}>{$value}</td>\n";
        }
        echo "</tr>\n";
    }
    echo "</tbody></table>\n";
}