function ER_log_error($source, $message, $severity, $hint = "") { // Check presence of mandatory args if (empty($source) || empty($message) || empty($severity)) { $tmpmsg = "Cannot display error, wrong format."; $tmphint = "Check how you called ER_log_error() !"; ER_log_error("ER_log_error", $tmpmsg, ERWARN, $tmphint); return 0; } // Get the list of severities in our scope global $ER_crit_array; // Check validity of the criticity parameter (See top of // this file) if (!array_key_exists($severity, $ER_crit_array)) { $tmpmsg = "Cannot display error, wrong severity."; $tmphint = "Check how you called ER_log_error() !"; ER_log_error("ER_log_error", $tmpmsg, ERWARN, $tmphint); return 0; } // Get the global array in our scope global $ER_errors_to_display; // Clean the messages $source = htmlentities($source); $message = htmlentities($message); $hint = htmlentities($hint); // Finally, add the error message to the global array for later // displaying by ER_display_errors() ! $ER_errors_to_display[$severity][] = array($source, $message, $hint); }
function jas_searchObject($string, $objectType) { // Check presence of arguments if (empty($string) || empty($objectType)) { $source = "jas_searchObject"; $message = "Missing search string and/or object type !"; $hint = "Please specify \$string and \$objectType for this function."; $severity = ERWARN; ER_log_error($source, $message, $severity, $hint); return false; } // Clean arguments $string = DB_escape_string($string, 0); $objectType = DB_escape_string($objectType, 0); // Check object type value - This code is crappy, I need a way // not to hard code "user" and "printer". See below. if (!strcmp($objectType, "'user'") || !strcmp($objectType, "'printer'")) { $source = "jas_searchObject"; $message = "Wrong object type !"; $hint = "Please choose either 'printer or 'user' for \$objectType."; $severity = ERWARN; ER_log_error($source, $message, $severity, $hint); return false; } // Choose the MySQL field to query depending on // $objectType. This code is not very extensible and // thus is bound to change ;-) $queryField = !strcmp($objectType, "user") ? "user" : "printer"; // build the query $query = "SELECT {$queryField} FROM jobs_log WHERE {$queryField} LIKE"; $query .= " '%{$string}%' GROUP BY {$queryField} ORDER BY {$queryField} ASC"; // Run the query and return the result or log an error. if ($result = DB_query($query)) { //Assignment ! if (mysql_num_rows($result)) { while ($line = mysql_fetch_array($result)) { $return_array[] = $line[0]; } return $return_array; } else { return -1; } // TO BE CONTINUED.... } else { $source = "jas_searchObject"; $message = "Query failed !"; $hint = "Check for the query syntax, and that the MySQL host is up."; $severity = ERWARN; ER_log_error($source, $message, $severity, $hint); return false; } }
function displayRow($rowNumber, $print = 0) { if (!is_array($this->rows[$rowNumber])) { // Error $source = "table::displayRow()"; $message = "Missing row number !"; $hint = "Please provide \$rowNumber for this function."; $severity = ERWARN; ER_log_error($source, $message, $severity, $hint); return false; } $output = " <tr>\n"; foreach ($this->rows[$rowNumber] as $field) { $output .= " <td>"; $output .= !empty($field) ? $field : " "; $output .= "</td>\n"; } $output .= " </tr>\n"; if ($print) { echo $output; return true; } return $output; }
function DB_escape_string($string, $quote = 1) { // Stripslashes if slashes already present. if (get_magic_quotes_gpc()) { $string = stripslashes($string); } // Escape if not integer value. if (!is_numeric($string)) { // This one will fail if no connection to the SQL server, so: if ($string = @mysql_real_escape_string($string)) { // Assignment !!! $string = $quote == true ? "'{$string}'" : $string; } else { $string = "'" . mysql_escape_string($string) . "'"; $message = "Unable to real_escape string: " . mysql_error(); $hint = "This happens when the MySQL server cannot be reached: Check that it is up !"; ER_log_error("DB_escape_string", $message, ERWARN, $hint); } } return $string; }