-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_class.php
More file actions
226 lines (208 loc) · 5.97 KB
/
admin_class.php
File metadata and controls
226 lines (208 loc) · 5.97 KB
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
<?php
session_start();
Class Action {
private $db;
public function __construct() {
ob_start();
include 'db_connect.php';
$this->db = $conn;
}
function __destruct() {
$this->db->close();
ob_end_flush();
}
function login(){
extract($_POST);
$qry = $this->db->query("SELECT * FROM users where username = '".$username."' and password = '".$password."' ");
if($qry->num_rows > 0){
foreach ($qry->fetch_array() as $key => $value) {
if($key != 'passwors' && !is_numeric($key))
$_SESSION['login_'.$key] = $value;
}
if($_SESSION['login_type'] == 1)
return 1;
else
return 2;
}else{
return 3;
}
}
function logout(){
session_destroy();
foreach ($_SESSION as $key => $value) {
unset($_SESSION[$key]);
}
header("location:login.php");
}
function save_files(){
extract($_POST);
if(empty($id)){
if($_FILES['upload']['tmp_name'] != ''){
$fname = strtotime(date('y-m-d H:i')).'_'.$_FILES['upload']['name'];
$move = move_uploaded_file($_FILES['upload']['tmp_name'],'assets/uploads/'. $fname);
if($move){
$file = $_FILES['upload']['name'];
$file = explode('.',$file);
$chk = $this->db->query("SELECT * FROM files where SUBSTRING_INDEX(name,' ||',1) = '".$file[0]."' and folder_id = '".$folder_id."' and file_type='".$file[1]."' ");
if($chk->num_rows > 0){
$file[0] = $file[0] .' ||'.($chk->num_rows);
}
$data = " name = '".$file[0]."' ";
$data .= ", folder_id = '".$folder_id."' ";
$data .= ", description = '".$description."' ";
$data .= ", user_id = '".$_SESSION['login_id']."' ";
$data .= ", file_type = '".$file[1]."' ";
$data .= ", file_path = '".$fname."' ";
if(isset($is_public) && $is_public == 'on')
$data .= ", is_public = 1 ";
else
$data .= ", is_public = 0 ";
$save = $this->db->query("INSERT INTO files set ".$data);
if($save)
return json_encode(array('status'=>1));
}
}
}else{
$data = " description = '".$description."' ";
if(isset($is_public) && $is_public == 'on')
$data .= ", is_public = 1 ";
else
$data .= ", is_public = 0 ";
$save = $this->db->query("UPDATE files set ".$data. " where id=".$id);
if($save)
return json_encode(array('status'=>1));
}
}
function save_user(){
extract($_POST);
$data = " name = '$name' ";
$data .= ", username = '$username' ";
$data .= ", password = '$password' ";
$data .= ", type = '$type' ";
if(empty($id)){
$save = $this->db->query("INSERT INTO users set ".$data);
}else{
$save = $this->db->query("UPDATE users set ".$data." where id = ".$id);
}
if($save){
return 1;
}
}
function save_category(){
extract($_POST);
$data = " category = '$category' ";
if(empty($id)){
$save = $this->db->query("INSERT INTO category_list set ".$data);
if($save)
return 1;
}else{
$save = $this->db->query("UPDATE category_list set ".$data." where id =".$id);
if($save)
return 2;
}
}
function delete_category(){
extract($_POST);
$delete = $this->db->query("DELETE FROM category_list where id=".$id);
if($delete)
return 1;
}
function save_voting(){
extract($_POST);
$data = " title = '$title' ";
$data .= " , description = '$description' ";
if(empty($id)){
$save = $this->db->query("INSERT INTO voting_list set ".$data);
if($save)
return 1;
}else{
$save = $this->db->query("UPDATE voting_list set ".$data." where id =".$id);
if($save)
return 2;
}
}
function get_voting(){
extract($_POST);
$get = $this->db->query("SELECT * FROM voting_list where id=".$id);
if($get->num_rows > 0){
return json_encode($get->fetch_assoc());
}
}
function delete_voting(){
extract($_POST);
$delete = $this->db->query("DELETE FROM voting_list where id=".$id);
if($delete)
return 1;
}
function update_voting(){
extract($_POST);
$this->db->query("UPDATE voting_list set is_default = 0 where id !=".$id);
$update = $this->db->query("UPDATE voting_list set is_default = 1 where id= ".$id);
if($update)
return 1;
}
function save_opt(){
extract($_POST);
$data = " category_id = '".$category_id."' ";
$data .= ", opt_txt = '".$opt_txt."' ";
$data .= ", voting_id = '".$voting_id."' ";
if($_FILES['img']['tmp_name'] != ''){
$fname = strtotime(date('y-m-d H:i')).'_'.$_FILES['img']['name'];
$move = move_uploaded_file($_FILES['img']['tmp_name'],'assets/img/'. $fname);
$data .= ", image_path = '".$fname."' ";
if(!empty($id)){
$path = $this->db->query("SELECT * FROM voting_opt where id=".$id)->fetch_array()['image_path'];
if(!empty($path))
unlink('assets/img/'.$path);
}
}
if(empty($id)){
$save = $this->db->query("INSERT INTO voting_opt set ".$data);
if($save)
return 1;
}else{
$save = $this->db->query("UPDATE voting_opt set ".$data." where id=".$id);
if($save)
return 2;
}
}
function delete_candidate(){
extract($_POST);
$path = $this->db->query("SELECT * FROM voting_opt where id=".$id)->fetch_array()['image_path'];
$delete = $this->db->query("DELETE FROM voting_opt where id=".$id);
if($delete){
unlink('assets/img/'.$path);
return 1;
}
}
function save_settings(){
extract($_POST);
$data = " category_id = $category_id ";
$data .= ", voting_id = $voting_id ";
$data .= ", max_selection = $max_selection ";
if(empty($id)){
$save = $this->db->query("INSERT INTO voting_cat_settings set ".$data);
}else{
$save = $this->db->query("UPDATE voting_cat_settings set ".$data." where id=".$id);
}
if($save)
return 1;
}
function submit_vote(){
extract($_POST);
$set = 0;
foreach($opt_id as $k => $val){
foreach ($val as $key => $v) {
$data = " voting_id = $voting_id ";
$data .= ", category_id = $k ";
$data .= ", user_id = '".$_SESSION['login_id']."' ";
$data .= ", voting_opt_id = $v ";
// echo $data.'<br>';
$save[] = $this->db->query("INSERT INTO votes set ".$data);
$set++;
}
}
if(isset($save) && count($save) == $set)
return 1;
}
}