-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
129 lines (117 loc) · 4.67 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
function sanitizeString($var)
{
$var = strip_tags($var);
$var = htmlentities($var);
$var = stripslashes($var);
return mysql_real_escape_string($var);
}
function load_options($table, $selected) {
// virtual choise creator
// choose if it will be prechosen
if ($selected == -1)
$extra_attribute='selected="selected"';
else $extra_attribute='';
// this is the view of the virtual choise
echo '<option value="-1" '.$extra_attribute.'>--επιλέξτε--</option>';
// generate of <options>
// records of $table (as a parameter of function)
try {
require('../parameteDB.php'); //database connect parameters
//initialization of PDObject and query creator
$pdoObject = new PDO("mysql:host=$dbhost;dbname=$dbname;", $dbuser, $dbpass);
$pdoObject -> exec('set names utf8');
$sql = "SELECT * FROM $table";
// instant query to sql because
// no input given from user
$statement = $pdoObject->query($sql);
// repetitive get of the results from the statement
while ( $record = $statement->fetch() ) {
// case of preselected <option>
if ($record[0]==$selected)
$extra_attribute='selected="selected"';
else $extra_attribute='';
//display of the <option>
echo '<option value="'.$record[0].'" '.$extra_attribute.'>'.$record[1].'</option>';
}
// clearance of the PDObject
$statement->closeCursor();
$pdoObject=null;
} catch (PDOException $e) { //block για exception handling
header('Location: index.php?msg=Πρόβλημα στις Κατηγορίες: '. $e->getMessage());
exit();
}
}
function load_options_sorted($table, $selected, $sorted) {
// virtual choise creator
// choose if it will be prechosen
if ($selected == -1)
$extra_attribute='selected="selected"';
else $extra_attribute='';
// this is the view of the virtual choise
echo '<option value="-1" '.$extra_attribute.'>--επιλέξτε--</option>';
// generate of <options>
// records of $table (as a parameter of function)
try {
require('../parameteDB.php'); //database connect parameters
//initialization of PDObject and query creator
$pdoObject = new PDO("mysql:host=$dbhost;dbname=$dbname;", $dbuser, $dbpass);
$pdoObject -> exec('set names utf8');
$sql = "SELECT * FROM $table ORDER BY $sorted";
// instant query to sql because
// no input given from user
$statement = $pdoObject->query($sql);
// repetitive get of the results from the statement
while ( $record = $statement->fetch() ) {
// case of preselected <option>
if ($record[0]==$selected)
$extra_attribute='selected="selected"';
else $extra_attribute='';
//display of the <option>
echo '<option value="'.$record[0].'" '.$extra_attribute.'>'.$record[1].'</option>';
}
// clearance of the PDObject
$statement->closeCursor();
$pdoObject=null;
} catch (PDOException $e) { //block για exception handling
header('Location: index.php?msg=Πρόβλημα στις Κατηγορίες: '. $e->getMessage());
exit();
}
}
function load_options_under_condition($table, $selected, $column, $condition) {
// virtual choise creator
// choose if it will be prechosen
if ($selected == -1)
$extra_attribute='selected="selected"';
else $extra_attribute='';
// this is the view of the virtual choise
echo '<option value="-1" '.$extra_attribute.'>--επιλέξτε--</option>';
// generate of <options>
// records of $table (as a parameter of function)
try {
require('../parameteDB.php'); //database connect parameters
//initialization of PDObject and query creator
$pdoObject = new PDO("mysql:host=$dbhost;dbname=$dbname;", $dbuser, $dbpass);
$pdoObject -> exec('set names utf8');
$sql = "SELECT * FROM $table WHERE $column = $condition";
// instant query to sql because
// no input given from user
$statement = $pdoObject->query($sql);
// repetitive get of the results from the statement
while ( $record = $statement->fetch() ) {
// case of preselected <option>
if ($record[0]==$selected)
$extra_attribute='selected="selected"';
else $extra_attribute='';
//display of the <option>
echo '<option value="'.$record[0].'" '.$extra_attribute.'>'.$record[1].'</option>';
}
// clearance of the PDObject
$statement->closeCursor();
$pdoObject=null;
} catch (PDOException $e) { //block για exception handling
header('Location: index.php?msg=Πρόβλημα στις Κατηγορίες: '. $e->getMessage());
exit();
}
}
?>