-
Notifications
You must be signed in to change notification settings - Fork 0
/
essential.php
132 lines (119 loc) · 2.94 KB
/
essential.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
129
130
<?php
session_start();
$con = 0;
function check_login(){
if(!isset($_SESSION['user'])){
header('Location:index.php');
}
}
function generate_list($q,$x,$isnull = true){
$r = execute($q);
$i=0;
$rowcount = mysql_num_rows($r);
$st = "<select name='" . $x . "' id='" . $x . "'>";
if($isnull) $st .= "<option value='' >--Please select--</option>";
while($row = mysql_fetch_array($r,MYSQL_NUM)){
$st .= "<option value='".$row[0]."' id='".$row[0]."'>".$row[0]."</option>";
}
$st .= "</select>";
return $st;
}
function generate_timeslot($myid){
$st = "<select name='". $myid . "' id='". $myid." >";
$st .= "<option value='' id='fg'>Please select</option>";
for($i=0;$i<24;$i++){
$dig=0;
$k = $i;
while($k>0){
$k/=10;
$dig++;
}
$j = $i.'';
if($i<10){
$j = '0' . $j;
}
$j1 = $j.":00:00";
$j2 = $j.":30:00";
$st .= "<option value='" . $j1 . "' name='" . $j1 . "' id='" .$j1."'>".$j1."</option>";
$st .= "<option value='" . $j2 . "' name='" . $j2 . "' id='" .$j2."'>".$j2."</option>";
}
$st .= "</select>";
return $st;
}
function execute($q){
GLOBAL $con;
if($con == 0 ){
dbconnect();
}
$r = mysql_query($q,$con);
if(!$r){
die("Cannot execute the query".$q);
}
else{
return $r;
}
}
function dbconnect(){
GLOBAL $con;
$con = mysql_connect('localhost','root','sqlpassword');
if(!$con){
die("no connection");
}
else {
$q = "use Tiles";
$rv = mysql_query( $q , $con);
if(!$rv){
die("no database!");
}
}
}
function escape($x){
$x = stripslashes($x);
$x = mysql_real_escape_string($x);
return ($x);
}
function make_array($a){
$all = array();
while($row = mysql_fetch_array($a))
{
$all[] = $row[0];
}
return $all;
}
function paginate($file,$myquery,$start=0,$lim=10)
{
$query1 = $myquery.";";
$result=execute($query1);
$num = mysql_num_rows($result);
if($num == 0)
{
return $result;
}
$back = $start - $lim;
$next = $start + $lim;
$query2= $myquery." limit ".$start.",".$lim.";";
$result2=execute($query2);
echo mysql_error();
$index=1;
if($num > $lim){ // display links only if records are enuf.
if($back >=0){
echo"<a href='".$file."?st=".$back."'>PREV</a>";
}
for($i=0;$i<$num;$i=$i+$lim){
if($i != $start){
echo" <a href='".$file."?st=".$i."'>";
echo ' '.$index;
echo "</a>";
}
else{
echo ' ';
echo $index;
}
$index = $index+1;
}
if($next < $num){
echo" <a href='".$file."?st=".$next."'> NEXT</a>";
}
}
return $result2;
}