echo dbFlexigrid(function ($limit, $sortname, $sortorder) { global $db_query_info; $db_query_info = array(); $db_query_info['type'] = 'profiling'; if (!userIsAdmin()) { return "Error"; } global $wpdb; $L = getSoft($_POST, 'frequency', ''); if (!is_numeric($L) || $L <= 0) { $L = 10; } $A = getSoft($_POST, 'activity', ''); if ($A == 'all' || $A == '') { $where = ""; } else { if ($A == 'noDatabases') { $where = "WHERE activity NOT LIKE 'database%'"; } else { if ($A == 'databases') { $where = "WHERE activity LIKE 'database%'"; } else { $where = $wpdb->prepare("WHERE activity LIKE %s", $A); } } } $sortString = trim($sortname) == "" ? "" : " {$sortname} {$sortorder} "; $count = $wpdb->get_var("\nSELECT count(distinct activity, substring(start, 1, {$L}))\nFROM " . $wpdb->prefix . "pb_profiling\n{$where}"); $query = "\nSELECT substring(start, 1, {$L}) as period, count(1), sum(duration), activity\nFROM " . $wpdb->prefix . "pb_profiling\n{$where}\nGROUP BY activity, period\nORDER BY {$sortString} period DESC\n{$limit}"; $id = 0; $flexirows = array(); foreach ($wpdb->get_results($query, ARRAY_A) as $r) { $cell = array(); foreach ($r as $i => $v) { $cell[$i] = $v; } $flexirows[] = array('id' => $r['period'] . $r['activity'], 'cell' => $cell); } return array('total' => $count, 'rows' => $flexirows); });
$prep = "\nSELECT userid, ID, beginstamp, usercode, userinput, result, problem\nFROM " . $wpdb->prefix . "pb_submissions \nWHERE {$whereStudent} AND {$whereProblem}\nORDER BY {$sortString} ID DESC " . $limit; $flexirows = array(); foreach ($wpdb->get_results($prep, ARRAY_A) as $r) { $cell = array(); if ($u == "all") { $cell[__t('userid')] = str_replace(' ', "<br>", userString($r['userid'], true)); } $p = $r['problem']; if (array_key_exists($p, $problemTable)) { $cell[__t('problem')] = '<a class="open-same-window" href="' . $problemTable[$p]->url . '">' . $problemTable[$p]->publicname . '</a>'; } else { $cell[__t('problem')] = $p; } $cell[__t('user code')] = preBox($r['usercode'], -1, -1); $cell[__t('user input')] = $r['userinput'] == NULL ? '<i>' . __t('n/a') . '</i>' : preBox($r['userinput'], -1, 100000); if ($p != 'visualizer' && $p != 'visualizer-iframe') { $cell[__t('result')] = getSoft($resultdesc, $r['result'], '???'); } else { $cell[__t('result')] = '<i>n/a</i>'; } $cell[__t('time & ID')] = str_replace(' ', '<br/>', $r['beginstamp']) . '<br/>#' . $r['ID']; $flexirows[] = array('id' => $r['ID'], 'cell' => $cell); } return array('total' => $count, 'rows' => $flexirows); } // only do this if calld directly if (strpos($_SERVER["SCRIPT_FILENAME"], '/db-entire-history.php') != FALSE) { require_once "db-include.php"; echo dbFlexigrid('dbEntireHistory'); } // paranoid against newline error
} $table_name = $wpdb->prefix . "pb_mail"; $knownFields = array(__t("from") => "ufrom", __t("to") => "uto", __t("when") => "time", __t("message") => "body", __t("problem") => "problem", __t("replied?") => "unanswered"); $sortString = array_key_exists($sortname, $knownFields) ? $knownFields[$sortname] . " " . $sortorder . ", " : ""; $count = $wpdb->get_var("SELECT COUNT(1) from {$table_name} {$where}"); $prep = "SELECT * from {$table_name} {$where} ORDER BY {$sortString} ID DESC" . $limit; // pyboxlog($prep); $flexirows = array(); foreach ($wpdb->get_results($prep, ARRAY_A) as $r) { $cell = array(); $cell[__t('from')] = nicefiedUsername($r['ufrom']); $cell[__t('to')] = nicefiedUsername($r['uto']); $url = cscurl('mail') . "?who=" . $r['ustudent'] . "&what=" . $r['problem'] . "&which=" . $r['ID'] . "#m"; $cell[__t('when')] = str_replace(' ', '<br>', $r['time']); if ($what == '') { $cell[__t('problem')] = $r['problem']; } if ($unans == '') { $cell[__t('replied?')] = $r['unanswered'] == 1 ? __t('no') : __t('yes'); } $cell[__t('message')] = "<a href='{$url}'>" . preBox($r['body']) . "</a>"; $flexirows[] = array('id' => $r['ID'], 'cell' => $cell); } return array('total' => $count, 'rows' => $flexirows); } // only do this if calld directly if (strpos($_SERVER["SCRIPT_FILENAME"], '/db-mail.php') != FALSE) { require_once "db-include.php"; echo dbFlexigrid('dbMail'); } // paranoid against newline error
if ($count == 0) { return sprintf(__t('We do not have record of any submissions from user %1$s for problem %2$s.'), $uname . ' (#' . $uid . ')', $problemname); } $knownFields = array(__t("time & ID") => "beginstamp", __t("user code") => "usercode", __t("user input") => "userinput", __t("result") => "result"); if (array_key_exists($sortname, $knownFields)) { $sortString = $knownFields[$sortname] . " " . $sortorder . ", "; } else { $sortString = ""; } $prep = $wpdb->prepare("SELECT ID, beginstamp, usercode, userinput, result from {$table_name}\nWHERE userid = %d AND problem = %s ORDER BY {$sortString} ID DESC" . $limit, $uid, $problemname); $flexirows = array(); foreach ($wpdb->get_results($prep, ARRAY_A) as $r) { $cell = array(); $cell[__t('user code')] = preBox($r['usercode'], -1, -1); if ($showInputColumn) { $cell[__t('user input')] = $r['userinput'] === NULL ? '<i>' . __t('n/a') . '</i>' : preBox($r['userinput'], -1, 100000); } if ($problemname != "visualizer") { $cell[__t('result')] = getSoft($resultdesc, $r['result'], $r['result']); } $cell[__t('time & ID')] = str_replace(' ', '<br/>', $r['beginstamp']) . '<br/>#' . $r['ID']; $flexirows[] = array('id' => $r['ID'], 'cell' => $cell); } return array('total' => $count, 'rows' => $flexirows); } // only do this if calld directly if (strpos($_SERVER["SCRIPT_FILENAME"], '/db-problem-history.php') != FALSE) { require_once "db-include.php"; echo dbFlexigrid('dbProblemHistory'); } // paranoid against newline error
$complete_table = $wpdb->prefix . "pb_completed"; $count = $wpdb->get_var(userIsAdmin() ? "SELECT count(1) FROM {$user_table}" : $wpdb->prepare("SELECT count(1) FROM {$usermeta_table} WHERE meta_key=%s AND meta_value=%s", 'pbguru', $ulogin)); $students = $wpdb->get_results(userIsAdmin() ? "SELECT ID FROM {$user_table} {$limit}" : $wpdb->prepare("SELECT user_id AS ID FROM {$usermeta_table} WHERE meta_key=%s AND meta_value=%s {$limit}", 'pbguru', $ulogin)); // no sorting allowed due to weird nature of query $flexirows = array(); foreach ($students as $r) { $sid = $r->ID; $sdata = $wpdb->get_row($wpdb->prepare("SELECT usercode, beginstamp FROM {$submit_table} \n WHERE userid={$sid} and problem='%s' and result='Y'\n ORDER BY beginstamp DESC limit 1", $problemslug)); $s = get_userdata($sid); $cell = array(); $cell['ID'] = $sid; $cell['info'] = userString($sid); if ($sdata != null) { $cell[__t('latest correct')] = prebox($sdata->usercode); $cell[__t('last time')] = $sdata->beginstamp; $cell[__t('first time')] = $wpdb->get_var($wpdb->prepare("SELECT time FROM {$complete_table} WHERE userid={$sid} and problem='%s'", $problemslug)); } else { $cell[__t('latest correct')] = '<i>n/a</i>'; $cell[__t('last time')] = '<i>n/a</i>'; $cell[__t('first time')] = '<i>n/a</i>'; } $flexirows[] = array('id' => $sid, 'cell' => $cell); } return array('total' => $count, 'rows' => $flexirows); } // only do this if calld directly if (strpos($_SERVER["SCRIPT_FILENAME"], '/db-problem-summary.php') != FALSE) { require_once "db-include.php"; echo dbFlexigrid('dbProblemSummary'); } // paranoid against newline error