1: <?php
2: /*
3: ***********************************************************************************
4: DaDaBIK (DaDaBIK is a DataBase Interfaces Kreator) http://www.dadabik.org/
5: Copyright (C) 2001-2007 Eugenio Tacchini
6:
7: This program is free software: you can redistribute it and/or modify
8: it under the terms of the GNU General Public License as published by
9: the Free Software Foundation, either version 3 of the License, or
10: (at your option) any later version.
11:
12: This program is distributed in the hope that it will be useful,
13: but WITHOUT ANY WARRANTY; without even the implied warranty of
14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: GNU General Public License for more details.
16:
17: You should have received a copy of the GNU General Public License
18: along with this program. If not, see <http://www.gnu.org/licenses/>.
19:
20: If you want to contact me by e-mail, this is my address: eugenio.tacchini@unicatt.it
21: ***********************************************************************************
22: */
23: ?>
24: <?php
25:
26: function display_sql($sql)
27: // goal: display a sql query
28: // input: $sql
29: // output: nothing
30: // global: $display_sql
31: {
32: global $display_sql;
33: if ($display_sql == "1"){
34: echo "<p><strong style='color:#ff0000;'>Your SQL query (for debugging purpose): </strong>".$sql."</p>";
35: } // end if
36: } // end function display_sql
37:
38: function txt_out($message, $class="")
39: // goal: display text
40: // input: $message, $font_size, $font_color, $bold (1 if bold)
41: // output: nothing
42: {
43: if ( $class != "") {
44: $message = "<span class='$class'>$message</span>";
45: }
46: echo $message;
47: } // end function txt_out
48:
49: function get_pages_number($results_number, $records_per_page)
50: // goal: calculate the total number of pages necessary to display results
51: // input: $results_number, $records_per_page
52: // ouptut: $pages_number
53: {
54: $pages_number = $results_number / $records_per_page;
55: $pages_number = (int)($pages_number);
56: if (($results_number % $records_per_page) != 0) $pages_number++; // if the reminder is greater than 0 I have to add a page because I have to round to excess
57:
58: return $pages_number;
59: } // end function get_pages_number
60:
61: function build_date_select ($field_name, $day, $month, $year)
62: // goal: build three select to select a data (day, mont, year), if are set $day, $month and $year select them
63: // input: $field_name, the name of the date field, $day, $month, $year (or "", "", "" if not set)
64: // output: $date_select, the HTML date select
65: // global $start_year, $end_year
66: {
67: global $start_year, $end_year, $year_field_suffix, $month_field_suffix, $day_field_suffix;
68:
69: $date_select = "";
70: $day_select = "";
71: $month_select = "";
72: $year_select = "";
73:
74: $day_select .= "<select name=\"".$field_name.$day_field_suffix."\">";
75: $month_select .= "<select name=\"".$field_name.$month_field_suffix."\">";
76: $year_select .= "<select name=\"".$field_name.$year_field_suffix."\">";
77:
78: for ($i=1; $i<=31; $i++){
79: $day_select .= "<option value=\"".sprintf("%02d",$i)."\"";
80: if($day != "" and $day == $i){
81: $day_select .= " selected";
82: } // end if
83: $day_select .= ">".sprintf("%02d",$i)."</option>";
84: } // end for
85:
86: for ($i=1; $i<=12; $i++){
87: $month_select .= "<option value=\"".sprintf("%02d",$i)."\"";
88: if($month != "" and $month == $i){
89: $month_select .= " selected";
90: } // end if
91: $month_select .= ">".sprintf("%02d",$i)."</option>";
92: } // end for
93:
94: for ($i=$start_year; $i<=$end_year; $i++){
95: $year_select .= "<option value=\"$i\"";
96: if($year != "" and $year == $i){
97: $year_select .= " selected";
98: } // end if
99: $year_select .= ">".$i."</option>";
100: } // end for
101:
102: $day_select .= "</select>";
103: $month_select .= "</select>";
104: $year_select .= "</select>";
105:
106: $date_select = "<td valign=\"top\">".$day_select."</td><td valign=\"top\">".$month_select."</td><td valign=\"top\">".$year_select."</td>";
107:
108: return $date_select;
109:
110: } // end function build_date_select
111:
112: function contains_numerics($string)
113: // goal: verify if a string contains numbers
114: // input: $string
115: // output: true if the string contains numbers, false otherwise
116: {
117: $count_temp = strlen($string);
118: if(preg_match("/[0-9]+/", $string)) {
119: return true;
120:
121: }
122: return false;
123: } // end function contains_numerics
124:
125: function is_valid_email($email)
126: // goal: chek if an email address is valid, according to its syntax
127: // input: $email
128: // output: true if it's valid, false otherwise
129: {
130: return (preg_match(
131: '/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+'. // the user name
132: '@'. // the ubiquitous at-sign
133: '([-0-9A-Z]+\.)+' . // host, sub-, and domain names
134: '([0-9A-Z]){2,4}$/i', // top-level domain (TLD)
135: trim($email)));
136: } // end function is_valid_email
137:
138: function is_valid_url($url)
139: // goal: check if an url address is valid, according to its syntax, supports 4 letters domains (e.g. .info), http https ftp protcols and also port numbers
140: // input: $url
141: // output: true if it's valid, false otherwise
142: {
143: return preg_match("/^((ht|f)tps*://)((([a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4}))|(([0-9]{1,3}\.){3}([0-9]{1,3})))(:[0-9]{1,4})*((/|\?)[a-z0-9~#%&'_\+=:\?\.-]*)*)$/i", $url);
144: } // end function is_valid_url
145:
146: ?>