function debug_line() { if (!USE_NOP_DEBUG) { return; } $bt = debug_backtrace(); $bt = $bt[0]; $line = $bt['line']; $file = $bt['file']; debug_array("FILE={$file} LINE={$line}"); }
function fetchAuthority($schema, $aid) { $authority = scraperwiki::select("* FROM {$schema}.authorities WHERE name='{$aid}'"); debug_array($authority[0], "Fetched {$schema} authority {$aid}:"); return $authority[0]; }
/** function that retrieves data for the Payable report * @param type * * @return array */ function retrievePayableReport($type) { $expense_type = $this->config->item('expense_type'); $expense_type_key = $this->config->item('expense_type_key'); $monthlist = $this->config->item('monthlist'); $payables = $this->config->item('payables'); $query = "SELECT t1.month"; $first_subquery = TRUE; $total = array(); foreach ($payables as $key => $value) { $query .= ",t" . $key . "." . $key; $total[$key] = 0; } $query .= " FROM "; foreach ($payables as $key => $value) { if (!$first_subquery) { $query .= 'LEFT JOIN '; } $query .= '(SELECT month,SUM(amount) as "' . $key . '" FROM (`tbl_expense`) WHERE `type` = 4 and payable_id=' . $key . ' group by month) as t' . $key . ' '; if (!$first_subquery) { $query .= ' on t' . $key . '.month=t1.month '; } $first_subquery = FALSE; } /*$query=$this->db->query('SELECT t1.month,t1.1,t2.2,t3.3 FROM (SELECT month,SUM(amount) as "1" FROM (`tbl_expense`) WHERE `type` = 4 and payable_id=1 group by month) as t1 LEFT JOIN (SELECT month,SUM(amount) as "2" FROM (`tbl_expense`) WHERE `type` = 4 and payable_id=2 group by month) as t2 on t2.month=t1.month LEFT JOIN (SELECT month,SUM(amount) as "3" FROM (`tbl_expense`) WHERE `type` = 4 and payable_id=3 group by month) as t3 on t3.month=t1.month'); */ $query = $this->db->query($query); $temp = $query->result_array(); $sn = 1; foreach ($temp as $key1 => $value1) { $temp[$key1]['sn'] = $sn; $temp[$key1]['month'] = $monthlist[$temp[$key1]['month']]; //now sum up the total for each type of payable foreach ($payables as $key2 => $value2) { $total[$key2] = $total[$key2] + $temp[$key1][$key2]; } $sn++; } if (!empty($temp)) { $temp[$sn] = array('sn' => ' ', 'month' => 'Total'); foreach ($payables as $key => $value) { $temp[$sn][$key] = $total[$key]; } } debug_array($temp); return $temp; }
function getrandquote() { // build array of approved quotes, then pick random ids out of that array and build the SQL // for that and get the regular text, etc. $qlist = getallappquote(); // list of all quotes that are approved if (!is_array($qlist)) { return false; } $randlist = array_rand($qlist, qlim); // grab qlim number of array keys from big list for ($i = 0; $i < count($randlist); $i++) { /* build an array of actual quoteids from the full list, getting the quoteid value using the randomnly generated key array ($randlist) */ $quotelist[$i] = $qlist[$randlist[$i]]; } // debug_array($quotelist); // debug_array($randlist); if (count($quotelist) > 0) { // $q will be the final list of quotes to ask the database for $q = implode(",", $quotelist); // these babies could use up a fair whack of memory I bet unset($randlist, $qlist, $quotelist); } else { // this will only happen if there are no quotes return false; } $sql = "select * from " . tbl_quote . " where " . col_qid . " in (" . $q . ");"; $qres = doquery_fa($sql); if (debug == 1) { debug_sqlfnc($sql, mysql_error()); debug_array($qres); } return $qres; }
/** * http://se2.php.net/manual/en/function.print-r.php#75872 * * An alternative to print_r that unlike the original does not use output buffering with * the return parameter set to true. Thus, Fatal errors that would be the result of print_r * in return-mode within ob handlers can be avoided. * * Comes with an extra parameter to be able to generate html code. If you need a * human readable DHTML-based print_r alternative, see http://krumo.sourceforge.net/ * * Support for printing of objects as well as the $return parameter functionality * added by Fredrik Wollsén (fredrik dot motin at gmail), to make it work as a drop-in * replacement for print_r (Except for that this function does not output * paranthesises around element groups... ;) ) * * Based on return_array() By Matthew Ruivo (mruivo at gmail) * (http://se2.php.net/manual/en/function.print-r.php#73436) */ function debug_array($var, $return = false, $html = false, $level = 0) { $spaces = ""; $space = $html ? " " : " "; $newline = $html ? "<br />" : "\n"; for ($i = 1; $i <= 6; $i++) { $spaces .= $space; } $tabs = $spaces; for ($i = 1; $i <= $level; $i++) { $tabs .= $spaces; } if (is_array($var)) { $title = "Array"; } elseif (is_object($var)) { $title = get_class($var) . " Object"; } $output = $title . $newline . $newline; foreach ($var as $key => $value) { if (is_array($value) || is_object($value)) { $level++; $value = debug_array($value, true, $html, $level); $level--; } $output .= $tabs . "[" . $key . "] => " . $value . $newline; } if ($return) { return $output; } else { echo $output; } }
function debug_screen() { global $debug_log_array, $debug_warning_array, $debug_notice_array, $debug_unknow_array, $debug_sql_array, $debug_sql_error, $_path, $Account_Data, $Stats_Data, $installing, $active_debug; if ($installing || verif_access("Admin", true) && $active_debug) { $html = ""; $corrig_path = str_replace("/", '\\', $_path); if (!empty($debug_log_array)) { $content = ""; $content .= "<table border='1'>"; if (isset($debug_log_array)) { foreach ($debug_log_array as $x => $req) { foreach ($req['trace'] as $n => $t) { if ($n != 0 && $t['function'] !== 'debug_log') { $content .= "<tr>"; if ($n == 1) { $content .= "<th rowspan='" . (count($req['trace']) - 1) . "'>{$x}</th><td rowspan='" . (count($req['trace']) - 1) . "' >" . $req['message'] . "</td>"; } $content .= "<td>" . (isset($t['file']) ? str_replace($corrig_path, "", $t['file']) : "") . "</td>\n\t\t\t\t\t\t\t\t<td>" . (isset($t['line']) ? $t['line'] : '') . "</td>\n\t\t\t\t\t\t\t\t<td>" . $t['function'] . "</td>\n\t\t\t\t\t\t\t\t<td>" . print_r($t['args'], 1) . "</td>"; $content .= "</tr>"; } } } } $content .= "</table>"; $html .= show_debug("log", "Log", $content); } if (!empty($Account_Data) && verif_connect(true)) { $content = ""; $content .= debug_array($Stats_Data); $content .= debug_array($Account_Data); $html .= show_debug("perso", "Avatar", $content); } if (!empty($_SESSION)) { $html .= show_debug("session", "Session", debug_array($_SESSION)); } if (!empty($debug_sql_array)) { $content = ""; $content .= "<table border='1'>"; foreach ($debug_sql_array as $x => $req) { $content .= "<tr><th>{$x}</th><td>{$req}</td>"; if (isset($debug_sql_error[$x])) { $content .= "<td>" . $debug_sql_error[$x][0] . "</td>"; $content .= "<td>" . $debug_sql_error[$x][1] . "</td>"; $content .= "<td>" . $debug_sql_error[$x][2] . "</td>"; } $content .= "</tr>"; } $content .= "</table>"; $html .= show_debug("sql", "Requetes", $content); } if (!empty($_SERVER)) { $content = ""; $content .= "<table border='1'>"; $content .= debug_array($_SERVER); $content .= "</table>"; $html .= show_debug("server", "Serveur", $content); } if (!empty($debug_warning_array)) { $content = ""; $content .= "<table border='1'>"; foreach ($debug_warning_array as $x => $req) { $content .= "<tr>"; $content .= "<th>{$x}</th><td>" . $req['code'] . "</td><td>" . $req['message'] . "</td>"; $content .= "<td>" . str_replace($corrig_path, "", $req['file']) . "</td>\n\t\t\t\t\t<td>" . $req['line'] . "</td>"; if (isset($req['trace'])) { $content .= "<td><table>"; foreach ($req['trace'] as $n => $t) { if ($n != 0 && $t['function'] !== 'debug_log') { $content .= "<tr>"; $content .= "<td>" . (isset($t['file']) ? str_replace($corrig_path, "", $t['file']) : "") . "</td>\n\t\t\t\t\t\t\t\t<td>" . (isset($t['line']) ? $t['line'] : '') . "</td>\n\t\t\t\t\t\t\t\t<td>" . $t['function'] . "</td>\n\t\t\t\t\t\t\t\t<td>" . print_r($t['args'], 1) . "</td>"; $content .= "</tr>"; } } $content .= "</table></td>"; } $content .= "</tr>"; } $content .= "</table>"; $html .= show_debug("warning", "Alertes", $content, 2); } if (!empty($debug_notice_array)) { $content = ""; $content .= "<table border='1'>"; foreach ($debug_notice_array as $x => $req) { $content .= "<tr>"; $content .= "<th>{$x}</th>"; $content .= "<td>" . $req['code'] . "</td>"; $content .= "<td>" . $req['message'] . "</td>"; $content .= "<td>" . str_replace($corrig_path, "", $req['file']) . "</td>"; $content .= "<td>" . $req['line'] . "</td>"; $content .= "</tr>"; } $content .= "</table>"; $html .= show_debug("notice", "Avertissement", $content, 2); } if (!empty($debug_unknow_array)) { $content = ""; $content .= "<table border='1'>"; foreach ($debug_unknow_array as $x => $req) { $content .= "<tr>"; $content .= "<th>{$x}</th><td>" . $req['code'] . "</td><td>" . $req['message'] . "</td>"; $content .= "<td>" . str_replace($corrig_path, "", $req['file']) . "</td>\n\t\t\t\t\t<td>" . $req['line'] . "</td>"; $content .= "</tr>"; } $content .= "</table>"; $html .= show_debug("unknow", "Inconnu", $content, 2); } if (!empty($_FILES)) { $content = ""; $content .= "<table border='1'>"; foreach ($_FILES as $x => $req) { $content .= "<tr><th>{$x}</th><td>{$req}</td></tr>"; } $content .= "</table>"; $html .= show_debug("file", "Fichier", $content, 2); } if (!empty($_POST) || !empty($_GET)) { $content = ""; if (!empty($_POST)) { $content .= "<table border='1'>"; foreach ($_POST as $x => $req) { $content .= "<tr><th>{$x}</th><td>{$req}</td></tr>"; } $content .= "</table>"; } if (!empty($_GET)) { $content .= "<table border='1'>"; foreach ($_GET as $x => $req) { $content .= "<tr><th>{$x}</th><td>{$req}</td></tr>"; } $content .= "</table>"; } $html .= show_debug("request", "Formulaire", $content, 2); } /** $content = ""; $content .= "<table border='1'>"; $content .= debug_array(get_defined_functions()); $content .= "</table>"; $html .= show_debug("function","Fonctions",$content); $content = ""; $content .= "<table border='1'>"; $content .= debug_array(get_defined_constants(true)); $content .= "</table>"; $html .= show_debug("constants","Constantes",$content,2); $content = ""; $content .= "<table border='1'>"; $content .= debug_array(get_defined_vars()); $content .= "</table>"; $html .= show_debug("vars","Variables",$content); **/ return $html; } }