/
dbfunctions.php
263 lines (208 loc) · 6.32 KB
/
dbfunctions.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?php
ob_start();
// clean the variables
function cleanVars($vars){
$cleanVars = array();
foreach($vars as $varname => $value){
$clean = trim($value);
$clean = strip_tags($clean);
$clean = addslashes($clean); // use inplace of addslashes
$cleanVars[$varname] = $clean; //create sanitized array
}
return($cleanVars);
}
// insert function use to insert new entry in database and get new generated id
function insert($query){
$queryResponse = MYSQL_QUERY($query)or die($query." ". mysql_error());
if(is_resource($queryResponse)){
return mysql_fetch_array($queryResponse);
}else{
return mysql_insert_id();
}
}
// get functions use check and get the data from database
function get($query,$fetchType) {
$queryResponse = mysql_query($query)or die($query.mysql_error());
$dbReturnArray = array();
$i=0;
$fetchCommand="mysql_fetch_$fetchType";
while (@$queryResponseRow=$fetchCommand($queryResponse)) {
$dbReturnArray[$i]=$queryResponseRow;
$i++;
}
return $dbReturnArray;
}
// set function use to update and insert data
function set($query) {
$queryResponse = MYSQL_QUERY($query)or die($query." ". mysql_error());
if(is_resource($queryResponse)) {
return mysql_fetch_array($queryResponse);
}else{
return $queryResponse;
}
}
// delete method
function delete($query){
if(mysql_query($query)){
$success = "1";
}else{
$success = "0";
}
return $success;
}
//function for today date
function todaysDate(){
$tdate = date("Y-m-d", mktime(0,0,0, date("m"), date("d"), date("y")));
$tdate = $tdate." ".date('H:i:s');
return $tdate;
}
//function to create random password
function randomPassword() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //declare $pass as an array
$alphaLength = strlen($alphabet) - 1;
for ($i = 0; $i < 6; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass);
}
//function to create random password
function randomTwoDigits() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //declare $pass as an array
$alphaLength = strlen($alphabet) - 1;
for ($i = 0; $i < 2; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass);
}
// method use for send mail
function newPasswordSend($useremail,$usermessage){
$email_from = 'admin@gmail.com';
$to = $useremail;
$subject = "Password updated";
$message = $usermessage;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From:'.$email_from ."\r\n";
if(mail($to, $subject, $message, $headers)){
return true;
}else{
return false;
}
}
function sendMailtest($useremail,$message){
$email_from = 'admin@gmail.com';
$to = $useremail;
$subject = "Password updated";
$message = $usermessage;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From:'.$email_from ."\r\n";
if(mail($to, $subject, $message, $headers)){
return true;
}else{
return false;
}
}
function sendMail($email,$uniquecode,$emailEncrypt){
ini_set("SMTP", "aspmx.l.google.com");
$link = "http://www.cluzterz.com/browse/cms/agreementForm.php?email=".$emailEncrypt;
$temp = file_get_contents('mail_template.php');
$temp = str_replace('{{ link }}',$link,$temp);
$temp = str_replace('{{ uniquecode }}',$uniquecode,$temp);
$temp = str_replace('{{ emailEncrypt }}',$emailEncrypt,$temp);
$to = $email;
$subject = 'Business Code';
$mail_body = $temp."\r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From:donotreply@cluzterz.com' . "\r\n";
if(mail($to,$subject,$mail_body,$headers)){
$msg = array();
$msg['status']=1;
$msg['message']='Email has been delivered to admin';
//echo json_encode($msg);
}else{
$msg = array();
$msg['status']=0;
$msg['message']='Failed to deliver the message';
//echo json_encode($msg);
}
}
// check email validation
function validateEmail($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
// function to check user is validity
function isUserValid($id){
if($id >0){
// check users from table
$sql_check = "select * from users where userid ='".$id."'";
$res_check = get($sql_check,"array");
$row_check = count($res_check);
if($row_check>0){
if($res_check[0]['isactive'] == 1){
return true;
}elseif($res_check[0]['isactive'] == 0){
return false;
}
}else{
return false;
}
}else{
return false;
}
}
// user details through user id
function user_details($userid,$fieldname){
$fieldDetails = "";
//$sql = "SELECT `username`,`user_image` FROM `users` WHERE `userid`='".$userid."' and isactive='1'";
$sql = "SELECT $fieldname FROM `users` WHERE `userid`='".$userid."'";
$fun = get($sql,"assoc");
if(count($fun)>0){
$fieldDetails = $fun[0][$fieldname];
}
return $fieldDetails;
}
function deleteRow($query){
if(mysql_query($query)){
$success = "1";
}else{
$success = "0";
}
return $success;
}
function upload_image($imagename,$temp_name){
//$uploadDir = 'image_upload/'; //Uploading to same directory as PHP file
//$file = basename($_FILES['userfile']['name']);lookbook/images/thumbs/5582.jpg
$uploadDir = 'image_upload/';
$file = $imagename;
$ext = explode(".",$file);
$total = count($ext);
$ext = $ext[$total-1];
$newNameTime = time().".".$ext;
$newName = $uploadDir .$newNameTime;
/*$uploadFile = $file;
$randomNumber = rand(0, 99999);
$newName = $uploadDir . $randomNumber . $uploadFile;*/
if (is_uploaded_file($_FILES[$temp_name]['tmp_name'])) {
//echo "Temp file uploaded.";
} else {
}
if (move_uploaded_file($_FILES[$temp_name]['tmp_name'], $newName)) {
return $newNameTime;
//$imageName = 'cms/image_upload/'.$newNameTime;
//$JsonRating = array ('message'=>'File Uploaded Successfully','success'=>'1','imagename'=>$newName);
/*$JsonRating = array ('message'=>'File Uploaded Successfully','success'=>'1','imagename'=>$imageName);
echo json_encode($JsonRating);*/
}else{
$newNameTime = 0 ;
return $newNameTime;
/*$JsonRating = array ('message'=>'File Upload Fail','success'=>'0');
echo json_encode($JsonRating);*/
}
}
?>