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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
<?php
/***************************************
* Description:
* Autor: Robert Šmalc
* Created date: 01.03.2016
*****************************************/
namespace App\Controllers;
use Cache;
class FindController extends Controller
{
public function __construct()
{
parent::getGlobalVariables();
parent::getAllVariables();
}
/************************************************
* Get instance
************************************************/
private static $_instance;
public static function getInstance()
{
if (self::$_instance)
return self::$_instance;
return new FindController();
}
/**
* poisce, ce ima podani element parenta, ki je loop
*
*/
public static function find_parent_loop($element_spr, $element_if = 0)
{
$anketa = get('anketa');
$sql = sisplet_query("SELECT parent FROM srv_branching WHERE element_spr = '$element_spr' AND element_if = '$element_if' AND ank_id='$anketa'");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
$row = mysqli_fetch_array($sql);
if ($row['parent'] == 0) return 0;
$sql = sisplet_query("SELECT id FROM srv_if WHERE id = '$row[parent]' AND tip = '2'");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
if (mysqli_num_rows($sql) > 0)
return $row['parent'];
else
return self::find_parent_loop(0, $row['parent']);
}
/**
* poisce naslednjo vre_id v loopu
*
*/
public function findNextLoopId($if_id = 0)
{
if ($if_id == 0) {
$sql = sisplet_query("SELECT if_id FROM srv_loop_data WHERE id='" . get('loop_id') . "'");
$row = mysqli_fetch_array($sql);
$if_id = $row['if_id'];
$loop_id = get('loop_id');
}
else
$loop_id = 0;
$sql = sisplet_query("SELECT spr_id, max FROM srv_loop WHERE if_id = '$if_id'");
$row = mysqli_fetch_array($sql);
$spr_id = $row['spr_id'];
$max = $row['max'];
$spr = Cache::srv_spremenljivka($spr_id);
// Radio, checkbox, sn imena
if ($spr['tip'] == 2 || $spr['tip'] == 3 || $spr['tip'] == 9) {
$data_vrednost = array();
if ($spr['tip'] == 9)
$sql1 = sisplet_query("SELECT vre_id FROM srv_data_text" . get('db_table') . " WHERE spr_id='$spr_id' AND usr_id='" . get('usr_id') . "'");
else
$sql1 = sisplet_query("SELECT vre_id FROM srv_data_vrednost" . get('db_table') . " WHERE spr_id='$spr_id' AND usr_id='" . get('usr_id') . "'");
while ($row1 = mysqli_fetch_array($sql1)) {
$data_vrednost[$row1['vre_id']] = 1;
}
$vre_id = '';
$i = 1;
$sql = sisplet_query("SELECT lv.vre_id, lv.tip FROM srv_loop_vre lv, srv_vrednost v WHERE lv.if_id='$if_id' AND lv.vre_id=v.id ORDER BY v.vrstni_red ASC");
while ($row = mysqli_fetch_array($sql)) {
if ($row['tip'] == 0) { // izbran
if (isset($data_vrednost[$row['vre_id']])) {
$vre_id .= ', ' . $row['vre_id'];
$i++;
}
} elseif ($row['tip'] == 1) { // ni izbran
if (!isset($data_vrednost[$row['vre_id']])) {
$vre_id .= ', ' . $row['vre_id'];
$i++;
}
} elseif ($row['tip'] == 2) { // vedno
$vre_id .= ', ' . $row['vre_id'];
$i++;
} // nikoli nimamo sploh v bazi, zato ni potrebno nic, ker se nikoli ne prikaze
if ($i > $max && $max > 0) break;
}
$vre_id = substr($vre_id, 2);
if ($vre_id == '')
return null;
$sql = sisplet_query("SELECT l.id FROM srv_loop_data l, srv_vrednost v WHERE l.if_id='$if_id' AND l.id > '$loop_id' AND l.vre_id IN ($vre_id) AND l.vre_id=v.id ORDER BY l.id ASC");
if (!$sql) {
echo 'err56545' . mysqli_error($GLOBALS['connect_db']);
die();
}
$row = mysqli_fetch_array($sql);
if (mysqli_num_rows($sql) > 0)
return $row['id'];
else
return null;
}
// Number
elseif ($spr['tip'] == 7) {
$sql1 = sisplet_query("SELECT text FROM srv_data_text" . get('db_table') . " WHERE spr_id='$spr_id' AND usr_id='" . get('usr_id') . "'");
$row1 = mysqli_fetch_array($sql1);
$num = (int)$row1['text'];
$sql2 = sisplet_query("SELECT id FROM srv_loop_data WHERE if_id='$if_id' AND id <= '$loop_id'");
if (mysqli_num_rows($sql2) >= $num || (mysqli_num_rows($sql2) >= $max && $max > 0))
return null;
$sql = sisplet_query("SELECT id FROM srv_loop_data WHERE if_id='$if_id' AND id > '$loop_id'");
$row = mysqli_fetch_array($sql);
if (mysqli_num_rows($sql) > 0)
return $row['id'];
else
return null;
}
// Ranking
elseif ($spr['tip'] == 17) {
$data_vrednost = array();
$sql1 = sisplet_query("SELECT vre_id FROM srv_data_rating WHERE spr_id='$spr_id' AND usr_id='" . get('usr_id') . "' ORDER BY vrstni_red ASC");
while ($row1 = mysqli_fetch_array($sql1)) {
$data_vrednost[$row1['vre_id']] = 1;
}
$vre_id = '';
$i = 1;
$sql = sisplet_query("SELECT lv.vre_id, lv.tip FROM srv_loop_vre lv, srv_vrednost v WHERE lv.if_id='$if_id' AND lv.vre_id=v.id ORDER BY v.vrstni_red ASC");
while ($row = mysqli_fetch_array($sql)) {
if ($row['tip'] == 0) { // izbran
if (isset($data_vrednost[$row['vre_id']])) {
$vre_id .= ', ' . $row['vre_id'];
$i++;
}
} elseif ($row['tip'] == 1) { // ni izbran
if (!isset($data_vrednost[$row['vre_id']])) {
$vre_id .= ', ' . $row['vre_id'];
$i++;
}
} elseif ($row['tip'] == 2) { // vedno
$vre_id .= ', ' . $row['vre_id'];
$i++;
} // nikoli nimamo sploh v bazi, zato ni potrebno nic, ker se nikoli ne prikaze
if ($i > $max && $max > 0) break;
}
$vre_id = substr($vre_id, 2);
if ($vre_id == '')
return null;
// Ce gre za prvi loop poiscemo ranking odgovor na prvem mestu
if($loop_id == 0){
$sql = sisplet_query("SELECT l.id FROM srv_loop_data l, srv_data_rating dr
WHERE l.if_id='$if_id' AND l.id > '$loop_id' AND l.vre_id IN ($vre_id)
AND l.vre_id=dr.vre_id AND dr.usr_id='".get('usr_id')."' AND dr.vrstni_red = '1'
");
}
// Ce gre za kasnejsi loop poiscemo naslednji ranking odgovor
else{
$sql2 = sisplet_query("SELECT dr.vrstni_red FROM srv_loop_data l, srv_data_rating dr WHERE l.if_id='$if_id' AND l.id='$loop_id' AND dr.vre_id=l.vre_id AND dr.usr_id='".get('usr_id')."'");
if(mysqli_num_rows($sql2) > 0){
$row2 = mysqli_fetch_array($sql2);
$sql = sisplet_query("SELECT l.id FROM srv_loop_data l, srv_vrednost v, srv_data_rating dr
WHERE l.if_id='$if_id' AND l.id != '$loop_id' AND l.vre_id IN ($vre_id)
AND l.vre_id=v.id
AND dr.vre_id=v.id AND dr.usr_id='".get('usr_id')."' AND dr.vrstni_red > '".$row2['vrstni_red']."'
ORDER BY dr.vrstni_red ASC
");
}
else
return null;
}
if (!$sql) {
echo 'err56545' . mysqli_error($GLOBALS['connect_db']);
die();
}
$row = mysqli_fetch_array($sql);
if (mysqli_num_rows($sql) > 0)
return $row['id'];
else
return null;
}
}
/**
* @desc poisce prejsnjo stran - grupo, 0 pomeni konec
*/
public static function findPrevGrupa()
{
$anketa = get('anketa');
$grupa = get('grupa');
$sql = sisplet_query("SELECT vrstni_red FROM srv_grupa WHERE id = '$grupa'");
$row = mysqli_fetch_array($sql);
$vrstni_red = $row['vrstni_red'];
$sql = sisplet_query("SELECT id FROM srv_grupa WHERE ank_id='$anketa' AND vrstni_red<'$vrstni_red' ORDER BY vrstni_red DESC LIMIT 1");
// naslednja stran
if (mysqli_num_rows($sql) > 0) {
$row = mysqli_fetch_array($sql);
return $row['id'];
// konec
} else {
return 0;
}
}
/**
* @desc poisce naslednjo stran - grupo, 0 pomeni konec
*/
public function findNextGrupa($gru_id=0)
{
//vrstni red trenutne grupe
if (get('grupa') > 0) {
$sql = sisplet_query("SELECT vrstni_red FROM srv_grupa WHERE id = '" . get('grupa') . "'");
$row = mysqli_fetch_array($sql);
$vrstni_red = $row['vrstni_red'];
}
elseif ($gru_id > 0) {
$sql = sisplet_query("SELECT vrstni_red FROM srv_grupa WHERE id = '" . $gru_id . "'");
$row = mysqli_fetch_array($sql);
$vrstni_red = $row['vrstni_red'];
}
else {
$vrstni_red = 0;
}
$sql = sisplet_query("SELECT id FROM srv_grupa WHERE ank_id='" . get('anketa') . "' AND vrstni_red>'$vrstni_red' ORDER BY vrstni_red ASC LIMIT 1");
// naslednja stran
if (mysqli_num_rows($sql) > 0) {
$row = mysqli_fetch_array($sql);
return $row['id'];
}
// konec
else {
return 0;
}
}
}
|