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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
<?php
class SurveyStatusCasi
{
static private $sid = null; # id ankete
static private $uid = null; # id userja
static private $inited = false; # ali so profili ze inicializirani
static private $currentProfileId = null; # trenutno profil
static private $profiles = array(); # seznam vseh profilov od uporabnika
// lurker je mal poseben, ker je neodvisen od ostalih (user je npr. 6 in lurker)
static private $allStatus = array('null',0,1,2,3,4,5,6,'lurker'); // Statusi anket katere štejemo kot ustrezne
static private $appropriateStatus = array(6,5); // Statusi anket katere štejemo kot ustrezne
static private $unAppropriateStatus = array(4,3,2,1,0); // Statusi anket katere štejemo kot neustrezne
static private $unKnownStatus = array('null'); // Statusi anket katere štejemo kot neustrezne
static function Init($sid, $uid = null) {
# nastavimo surveyId
self::setSId($sid);
# nastavimo userja
self::setGlobalUserId($uid);
SurveyUserSetting :: getInstance()->Init(self::$sid, self::getGlobalUserId());
if (self::$inited == false) {
self::$inited = self :: RefreshData();
}
}
static function RefreshData() {
global $lang;
// Profila za status - prej smo imeli to v bazi ampak ni potrebe, ker sta itak samo 2 in ne pustimo vec custom profilov
self::$profiles['1'] = array(
'id' => '1',
'uid' => '0',
'name' => $lang['srv_userstatus_6'],
'system' => '1',
'statusnull' => '0',
'status0' => '0',
'status1' => '0',
'status2' => '0',
'status3' => '0',
'status4' => '0',
'status5' => '0',
'status6' => '1',
'statuslurker' => '0'
);
self::$profiles['2'] = array(
'id' => '2',
'uid' => '0',
'name' => $lang['srv_userstatus_total'],
'system' => '1',
'statusnull' => '1',
'status0' => '1',
'status1' => '1',
'status2' => '1',
'status3' => '1',
'status4' => '1',
'status5' => '1',
'status6' => '1',
'statuslurker' => '1'
);
# poiscemo privzet profil
self::$currentProfileId = SurveyUserSetting :: getInstance()->getSettings('default_status_casi');
if (!self::$currentProfileId || self::$currentProfileId == 1)
self::$currentProfileId = 1;
# ce imamo nastavljen curent pid in profil z tem pid ne obstaja nastavomo na privzet profil
if (self::$currentProfileId != 1) {
if (!isset(self::$profiles[self::$currentProfileId])) {
self::$currentProfileId = 1;
self::setDefaultProfileId(self::$currentProfileId);
}
}
# ce ne obstajajo podatki za cpid damo error
if (!isset(self::$profiles[self::$currentProfileId])) {
die("Profile data is missing!");
return false;
} else {
return true;
}
}
static function DisplayProfile( $pid = null) {
global $lang;
if ($pid == null ) {
$pid = self::$currentProfileId;
}
echo '<div id="status_profile_holder">';
self :: DisplayProfileOptions($pid);
echo '</div>';
echo '<div id="status_profile_data_holder">';
echo '<div>';
self :: DisplayProfileData($pid);
echo '</div>';
echo '<br><div class="floatRight">';
# shrani - pozeni
$run_lbl = ( $pid == 1 ) ? $lang['srv_run_profile'] : $lang['srv_save_run_profile'];
echo '<span class="floatRight spaceLeft" ><span class="buttonwrapper"><a class="ovalbutton ovalbutton_orange" href="#" onclick="statusCasiAction(\'run\'); return false;"><span>'.$run_lbl.'</span></a></span></span>';
# preklici
echo '<span class="floatRight spaceLeft" ><span class="buttonwrapper"><a class="ovalbutton ovalbutton_gray" href="#" onclick="statusCasiAction(\'cancle\'); return false;"><span>'.$lang['srv_close_profile'].'</span></a></span></span>';
# shrani kot nov profil
echo '<span class="floatRight spaceLeft" ><span class="buttonwrapper"><a class="ovalbutton ovalbutton_gray" href="#" onclick="statusCasiAction(\'newName\'); return false;"><span>'.$lang['srv_save_new_profile'].'</span></a></span></span>';
echo '</div>';
echo '</div>';
// cover Div
echo '<div id="statusProfileCoverDiv"></div>'."\n";
// div za shranjevanje novega profila
echo '<div id="newProfile">'.$lang['srv_missing_profile_name'].': '."\n";
echo '<input id="newProfileName" name="newProfileName" type="text" size="45" />'."\n";
echo '<span class="floatRight spaceLeft" ><span class="buttonwrapper"><a class="ovalbutton ovalbutton_orange" href="#" onclick="statusCasiAction(\'newSave\'); return false;"><span>'.$lang['srv_save_profile'].'</span></a></span></span>'."\n";
echo '<span class="floatRight spaceLeft" ><span class="buttonwrapper"><a class="ovalbutton ovalbutton_gray" href="#" onclick="showHideNewMissingProfile(\'false\'); return false;"><span>'.$lang['srv_close_profile'].'</span></a></span></span>'."\n";
echo '</div>'."\n";
// div za brisanje
echo '<div id="deleteProfileDiv">'.$lang['srv_missing_profile_delete_confirm'].': <b>' . self::$profiles[$pid]['name'] . '</b>?'."\n";
echo '<input id="deleteProfileId" type="hidden" value="' . $pid . '" />'."\n";
echo '<span class="floatRight spaceLeft" ><span class="buttonwrapper"><a class="ovalbutton ovalbutton_gray" href="#" onclick="statusCasiAction(\'deleteCancle\'); return false;"><span>'.$lang['srv_close_profile'].'</span></a></span></span>'."\n";
echo '<span class="floatRight spaceLeft" ><span class="buttonwrapper"><a class="ovalbutton ovalbutton_orange" href="#" onclick="statusCasiAction(\'deleteConfirm\'); return false;"><span>'.$lang['srv_delete_profile_yes'].'</span></a></span></span>'."\n";
echo '</div>'."\n";
}
static function DisplayProfileData($pid) {
global $lang;
$curentProfileData = self :: $profiles[$pid];
echo '<div id="statusProfileFieldsetHolder" >';
echo '<fieldset id="missingProfileFieldset">'."\n";
echo '<legend>' . $lang['srv_missing_profile_title4'] . '</legend>'."\n";
echo '<form name="" id="" autocomplete="off">'."\n";
$cnt = 1;
echo '<table><tr>';
// dodamo veljavne
foreach (self::$appropriateStatus as $index) {
if ($cnt&1)
echo '</tr><tr>';
echo '<td style="width:50%">'."\n";
echo '<label><input name="srv_userstatus[]" type="checkbox" id="' . $index . '"' .
($curentProfileData['status'.$index] == 1 ? ' checked="checked"' : '') . '/>'."\n";
echo $lang['srv_userstatus_' . $index]. " (".$index.")";
echo '</label></td>'."\n";
$cnt++;
}
// dodamo neveljavne
foreach (self::$unAppropriateStatus as $index) {
if ($cnt&1)
echo '</tr><tr>';
echo '<td style="width:50%">'."\n";
echo '<label><input name="srv_userstatus[]" type="checkbox" id="' . $index . '"' .
($curentProfileData['status'.$index] == 1 ? ' checked="checked"' : '') . '/>'."\n";
echo $lang['srv_userstatus_' . $index]. " (".$index.")";
echo '</label></td>'."\n";
$cnt++;
}
// dodamo null
foreach (self::$unKnownStatus as $index) {
if ($cnt&1)
echo '</tr><tr>';
echo '<td style="width:50%">'."\n";
echo '<label><input name="srv_userstatus[]" type="checkbox" id="' . $index . '"' .
($curentProfileData['status'.$index] == 1 ? ' checked="checked"' : '') . '/>'."\n";
echo $lang['srv_userstatus_' . $index]. " (".$index.")";
echo '</label></td>'."\n";
$cnt++;
}
echo '</tr></table>';
// lurkerji
echo '<hr><label><input type="checkbox" name="srv_userstatus[]" id="lurker" '.($curentProfileData['statuslurker'] == 1 ? ' checked="checked"' : '') . '> '.$lang['srv_lurkers'].'</label>';
echo '<div class="clr"></div>'."\n";
echo '</form>'."\n";
echo '</fieldset>'."\n";
echo '</div>'."\n";
}
static function DisplayProfileOptions($pid) {
global $lang;
echo '<div id="status_casi" class="select">';
foreach ( self::$profiles as $key => $profile ) {
echo '<div id="status_profile_'.$profile['id'].'" class="option' . ($profile['id'] == $pid ? ' active' : '') . '" value="' . $profile['id'] . '">' . $profile['name'] . '</div>';
}
echo '</div>';
echo '<div id="status_profile_links" class="link_no_decoration">';
if ($pid != 1)
echo '<a href="#" onclick="statusCasiAction(\'deleteAsk\'); return false;">'.$lang['srv_delete_profile'].'</a><br/>'."\n";
echo '</div>';
echo '<script>';
echo '$(function() {';
echo 'scrollToProfile("#status_profile_'.$pid.'");';
echo '});';
echo '</script>';
}
/** getProfiles
*
*/
static function getProfiles() {
return self::$profiles;
}
/** setSurveyId
*
*/
static function setSId($surveyId) {
self::$sid = $surveyId;
}
/** setGlobalUserId
*
*/
static function setGlobalUserId($uid = null) {
if ($uid == null) {
global $global_user_id;
self::$uid = $global_user_id;
} else {
self::$uid = $uid;
}
}
/** getGlobalUserId
*
*/
static function getGlobalUserId() {
return self::$uid;
}
static function getCurentProfileId() {
return self::$currentProfileId;
}
/**
*
* @param unknown_type $pid
*/
static function setCurentProfileId($pid) {
if ($pid < 1)
$pid = 1;
return self::$currentProfileId = $pid;
}
static function setDefaultProfileId($pid) {
if (!$pid)
$pid = 1;
SurveyUserSetting :: getInstance()->saveSettings('default_status_casi', $pid);
self::$currentProfileId = $pid;
return true;
}
static function getStatusAsArrayString() {
$mpds = self::getStatusArray(self::$currentProfileId);
$result = array();
if ($mpds) {
foreach ( self::$appropriateStatus as $index) {
if (isset($mpds['status'.$index]) && $mpds['status'.$index] == 1)
$result[$index] = $index;
}
foreach ( self::$unAppropriateStatus as $index) {
if (isset($mpds['status'.$index]) && $mpds['status'.$index] == 1)
$result[$index] = $index;
}
foreach ( self::$unKnownStatus as $index) {
if (isset($mpds['status'.$index]) && $mpds['status'.$index] == 1)
$result[$index] = $index;
}
if (isset($mpds['statuslurker']) && $mpds['statuslurker'] == 1)
$result['lurker'] = 'lurker';
}
return $result;
}
static function getStatusArray($pid) {
$mpd = self::$profiles[$pid];
return $mpd;
}
/** Shranimo v obstoječ profil
*
* @param unknown_type $pid
* @param unknown_type $name
* @param unknown_type $status
*/
static function saveProfile($pid,$status) {
$insert_id = 0;
if (isset($pid) && $pid != null && isset($status) && $status != null) {
if ($pid == 1) { # ce mamo privzet profil ga ne shranjujemo
return 1;
}
# imamo podatke, updejtamo profil v bazi
$statusi = explode(',',$status);
if (count(self::$allStatus) > 0 ) {
$updateString = "UPDATE srv_status_casi SET ";
$prefix = '';
foreach (self::$allStatus as $_status) {
$updateString .= $prefix . 'status'.$_status. ' = '.(in_array((string)$_status,$statusi) ? '1' : '0');
$prefix =', ';
}
$updateString .= " WHERE id = '".$pid."'";
}
$queryUpdate = sisplet_query($updateString)
or die(mysqli_error($GLOBALS['connect_db']));
return $pid;
}
}
/** Shranimo kot nov profil
*
* @param unknown_type $pid
* @param unknown_type $name
* @param unknown_type $status
*/
static function saveNewProfile($pid,$name,$status) {
$insert_id = 0;
if (isset($pid) && $pid != null && isset($name) && $name != null && isset($status) && $status != null) {
# imamo podatke, vstavimo nov profil v bazo
#id uid name system statusnull status0 status1 status2 status3 status4 status5 status6
$statusi = explode(',',$status);
$str_lbl = '';
$str_vle = '';
foreach ($statusi as $_status) {
$str_lbl .= ', status'.$_status;
$str_vle .= ', 1';
}
$insertString = "INSERT INTO srv_status_casi (uid,name,system".$str_lbl.") VALUES ('".self::getGlobalUserId()."', '".$name."', 0".$str_vle.")";
$queryInsert = sisplet_query($insertString)
or die(mysqli_error($GLOBALS['connect_db']));
$insert_id = mysqli_insert_id($GLOBALS['connect_db']);
}
return $insert_id;
}
static function Delete($pid) {
if ($pid != 1) {
$sqlDelete = sisplet_query("DELETE FROM srv_status_casi WHERE id = '$pid' AND `system` != '1'");
print_r("DELETE FROM srv_status_casi WHERE id = '$pid' AND `system` != '1'");
}
}
}
?>
|