-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheader.php
executable file
·205 lines (189 loc) · 4.57 KB
/
header.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
session_start();
require_once 'config.php';
if(!isset($_SESSION['password']))
{
echo<<<_END
<script type="text/javascript">
curpath=window.location.href;
var index = curpath.lastIndexOf("/")+1;
var filename = curpath.substr(index);
if(filename!="index.php")
window.location.replace("index.php");
</script>
_END;
}
$dbhost=$_ENV['DB_HOST'];
$dbname=$_ENV['DB_NAME'];
$dbuser= $_ENV['DB_USER'];
$dbpass= $_ENV['DB_PASS'];
$dbport = $_ENV['DB_PORT'];
$appname='TMStock';
global $con;
$con=mysqli_connect($dbhost,$dbuser,$dbpass, $dbname, $dbport);
function destroySession()
{
session_start();
$query="DELETE from online_students where studentid='$_SESSION[user]'";
$result=queryMysql($query);
$_SESSION=array();
if(session_id()!=""||isset($_COOKIE[session_name()]))
setcookie (session_name (),'',time()-2592000,'/');
session_destroy();
}
function sanitizeString($var)
{
global $con;
$var=strip_tags($var);
$var=htmlentities($var);
$var=stripslashes($var);
return mysqli_real_escape_string($con,$var);
}
function queryMysql($query)
{
global $con;
$result=mysqli_query($con,$query) or die(mysqli_error($con));
return $result;
}
function salt($password)
{
$salt1="*#@1";
$salt2="23#%";
$password=md5("$salt1$password$salt2");
return $password;
}
if(isset($_GET['application']))
{
$application=sanitizeString($_GET['application']);
if($application=="event")
{
$application="Event Management";
$business="Events";
}
elseif($application=="catering")
{
$application="Catering Management";
$business="Catering";
}
else
{
die("Something went wrong");
}
$_SESSION['application']=$application;
$_SESSION['business']=$business;
}
function columns()
{
$columns='';
foreach($_POST as $key=>$value)
{
$key=sanitizeString($key);
if(!is_array($value))
$columns=$columns.",".$key;
}
$columns=substr($columns, 1);
return $columns;
}
function values()
{
$values='';
foreach($_POST as $key=>$value)
{
if(!is_array($value))
{
$value=sanitizeString($value);
// $columns=$columns.",".$key;
if(!is_numeric($value))
$values=$values.","."'".$value."'";
else
$values=$values.",".$value;
}
}
// $columns=substr($columns, 1);
$values=substr($values, 1);
return $values;
}
function query($table)
{
$columns=columns($_POST);
$values=values($_POST);
$query="Insert into $table($columns) values($values)";
$result= queryMysql($query);
}
function id($id)
{
if($id<10)
{
$id="00".$id;
}
elseif($id>=10&&$id<100)
{
$id="0".$id;
}
return $id;
}
function ymdDate($date)
{
$date=str_replace('/', '-', $date);
$date=date('Y-m-d', strtotime($date));
return $date;
}
function dmyDate($date)
{
if($date!="1969-12-31")
{
$date=date('d-m-Y', strtotime($date));
$date=str_replace('-', '/', $date);
return $date;
}
}
function uploadimage($tempname,$saveto,$type,$max)
{
move_uploaded_file($tempname,$saveto);
$typeok=TRUE;
switch($type)
{
case "image/gif": $src=imagecreatefromgif($saveto); break;
case "image/jpeg": break;
case "image/pjpeg": $src=imagecreatefromjpeg($saveto); break;
case "image/png": $src=imagecreatefrompng($saveto); break;
default : $typeok=FALSE;
}
if($typeok)
{
list($w,$h)=getimagesize($saveto);
$tw=$w;
$th=$h;
if($w>$h&&$max<$w)
{
$th=$max/$w*$h;
$tw=$max;
}
elseif($h>$w&&$max<$h)
{
$tw=$max/$h*$w;
$th=$max;
}
elseif($max<$w)
{
$tw=$th=$max;
}
$jpeg_quality = 60;
//$img_r = imagecreatefromjpeg($saveto);
$tmp = ImageCreateTrueColor( $tw, $th );
// imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
//$targ_w,$targ_h,$_POST['w'],$_POST['h']);
//imagejpeg($dst_r,$saveto,$jpeg_quality);
// $tmp=imagecreatetruecolor($tw, $th);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $tw, $th, $w, $h);
//imageconvolution($tmp, array(
// array(-1,-1,-1),
// array(-1,16,-1),
// array(-1,-1,-1)
// ),8,0);
imagejpeg($tmp,$saveto,$jpeg_quality);
// imagedestroy($tmp);
// imagedestroy($src);
}
}
?>