Go to the source code of this file.
Functions | |
| db_query_mysql ($link, $q, $kw) | |
| perform a database query | |
| link_maybe ($text, $url, $condition) | |
| conditionally print text as a HTML hyperlink | |
| redirect ($url) | |
| redirect the user to a different URL | |
| param_ok ($allowed, $k, $v) | |
| check a parameter | |
| print_table ($table, $cols, $attr, $dblink, $subst) | |
| print a HTML table from a template | |
| normalize_input ($v) | |
| normalize user input | |
| print_header ($kw) | |
| print_footer ($kw) | |
| db_error_mysql () | |
| handle MySQL database errors | |
| error_msg ($msg) | |
Definition in file util.php.
| db_error_mysql | ( | ) |
handle MySQL database errors
determine the cause of error, print an appropriate error message, and exit
Definition at line 271 of file util.php.
References error_msg().
Referenced by db_query_mysql().
00271 { 00272 error_msg( "MYSQL: " . mysql_error() . " [" . mysql_errno() . "]" ); 00273 exit(0); 00274 }
Here is the call graph for this function:

Here is the caller graph for this function:

| db_query_mysql | ( | $ | link, | |
| $ | q, | |||
| $ | kw | |||
| ) |
perform a database query
| $link | open handle to the database | |
| $q | the SQL query | |
| $kw | text substitutions to be performed on $q |
Definition at line 32 of file util.php.
References $kw, $link, $q, $r, $v, and db_error_mysql().
Referenced by check_for_doubles(), export_to_pica(), fields_init(), and print_table().
00032 { 00033 00034 foreach ($kw as $k => $v) { 00035 $kw[$k] = mysql_escape_string($v); 00036 } 00037 00038 $q = strtr($q, $kw); 00039 00040 // print "query: " . $q . "<br>"; 00041 00042 ($r = @ mysql_query($q, $link)) or db_error_mysql(); 00043 00044 $result = array(); $i = 1; 00045 00046 if (@ mysql_num_rows($r) > 0) { 00047 while ($row = @ mysql_fetch_array($r)) { 00048 $result[$i++] = $row; 00049 } 00050 } 00051 00052 return $result; 00053 }
Here is the call graph for this function:

Here is the caller graph for this function:

| link_maybe | ( | $ | text, | |
| $ | url, | |||
| $ | condition | |||
| ) |
conditionally print text as a HTML hyperlink
| $text,$url,$condition | see below |
Definition at line 63 of file util.php.
References print.
00063 { 00064 if ($condition) 00065 print "<a href=\"$url\">$text</a>"; 00066 else 00067 print "<strong>$text</strong>"; 00068 }
| normalize_input | ( | $ | v | ) |
normalize user input
This function tries to deal with funny characters in user input by replacing them with harmless ones. It also strips blanks that are deemed unnecessary.
| $v | user input |
Definition at line 233 of file util.php.
References $v.
00233 { 00234 $v = preg_replace("/\\s+/", " ", $v); 00235 $v = preg_replace("/^ /", "", $v); 00236 $v = preg_replace("/ $/", "", $v); 00237 00238 $v = strtr($v, 'ÀÁÂÃÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕØÙÚÛÝàáâãåæçèéêëìíîïñòóôõøùúûýÿ', 00239 'AAAAAACEEEEIIIIDNOOOOOUUUYaaaaaaceeeeiiiinooooouuuyy'); 00240 00241 return $v; 00242 }
| param_ok | ( | $ | allowed, | |
| $ | k, | |||
| $ | v | |||
| ) |
check a parameter
This function is used to determine whether input to a script (received via GET or POST request) should be accepted by the script.
For example, to check whether $_GET['foo'] contains valid data you would test if param_ok($allowed, 'foo', $_GET['foo']) yields TRUE.
| $allowed | is an associative array containing regular expressions against which the input is matched | |
| $k | is a key into the $allowed[] array | |
| $v | is the input value to be checked |
Definition at line 113 of file util.php.
References $v.
00113 { 00114 00115 $ok = TRUE; 00116 00117 if (!isset($allowed[$k])) 00118 $ok = FALSE; 00119 else if (!preg_match($allowed[$k], $v)) 00120 $ok = FALSE; 00121 00122 return $ok; 00123 00124 }
| print_table | ( | $ | table, | |
| $ | cols, | |||
| $ | attr, | |||
| $ | dblink, | |||
| $ | subst | |||
| ) |
print a HTML table from a template
This function prints a HTML table from a template. See $table1 ... $table4 in action.php for examples of such templates.
| $table | the template | |
| $dblink | an open handle to the MySQL database | |
| $cols | the desired number of columns in the table | |
| $attr | the attributes of the HTML table (e.g. 'border="0"') | |
| $subst | a substitution table for db_query_mysql() |
Definition at line 139 of file util.php.
References $_SESSION, $f, $fields, $r, $v, db_query_mysql(), input_control(), and print.
00139 { 00140 00141 print "<table width=\"100%\" " . $attr . " >\n<tr>\n"; 00142 00143 $c = 1; 00144 00145 // $col_width1 = (35 / $cols); 00146 // $col_width2 = (65 / $cols); 00147 00148 if (empty($table)) 00149 return(TRUE); 00150 00151 foreach ($table as $row ) { 00152 00153 // do SQL query 00154 00155 00156 if (isset ($row["value"])) { 00157 00158 print "<td width=\"30%\"><strong>" . $row["label"] ; 00159 print "</strong></td>\n" ; 00160 print "<td>" . htmlentities(strtr($row["value"], $subst)) . "</td>"; 00161 00162 } else if (isset ($row["query"])) { 00163 00164 $r = db_query_mysql($dblink, $row["query"] , $subst); 00165 00166 if (empty($r)) { 00167 print "<td> </td>\n"; 00168 print "<td> </td>\n"; 00169 } else { 00170 00171 print "<td width=\"30%\"><strong>"; 00172 print $row["label"] . "</strong></td>\n"; 00173 00174 print "<td>"; 00175 00176 foreach ($r[1] as $k => $v) { 00177 if (is_numeric($k)) 00178 print htmlentities($v) . " "; 00179 } 00180 00181 print " </td>\n"; 00182 } 00183 } else if (isset($row["fields"])) { 00184 global $fields; 00185 00186 // print label 00187 00188 print "<td><strong>" . $row["label"] ; 00189 print "</strong></td>\n" ; 00190 00191 // print html form for user input 00192 00193 print "<td>"; 00194 00195 foreach ($row["fields"] as $f) { 00196 00197 // field key, field value 00198 $fk = $f; 00199 $fv = (isset($_SESSION[$fk])) ? 00200 $_SESSION[$fk] : ""; 00201 00202 print input_control($f, $fk, $fv ); 00203 print " "; 00204 } 00205 print "</td>\n"; 00206 00207 } else { 00208 print "<td> </td>\n"; 00209 print "<td> </td>\n"; 00210 } 00211 00212 if ($c < $cols){ 00213 $c++; 00214 } else { 00215 print "</tr>\n<tr>\n"; 00216 $c = 1; 00217 } 00218 } 00219 00220 print "</tr></table>"; 00221 00222 }
Here is the call graph for this function:

| redirect | ( | $ | url | ) |
redirect the user to a different URL
| $url | target url |
Definition at line 77 of file util.php.
References $kw, $text, $url, print, print_footer(), and print_header().
00077 { 00078 global $text; 00079 00080 $kw = array ('@bodyattr@' => "", 00081 '@notabene@' => "", 00082 '@url@' => "$url", 00083 '@url-de@' => "$url", 00084 '@url-en@' => "$url"); 00085 00086 header("Location: " . $url); 00087 00088 // for older browsers that don't support redirect 00089 00090 print_header($kw); 00091 print strtr($text['redirect'], $kw); 00092 print_footer($kw); 00093 exit(0); 00094 }
Here is the call graph for this function:

1.4.7