-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsharedgroupsFunctions.php
324 lines (261 loc) · 12.7 KB
/
sharedgroupsFunctions.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
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
<?php
//include js
function utt_sharedgroup_scripts(){
//load sharedgroupScripts.js file
wp_enqueue_script( 'sharedgroupScripts', plugins_url('js/sharedgroupScripts.js', __FILE__) );
//localize sharedgroup strings
wp_localize_script( 'sharedgroupScripts', 'sharedgroupStrings', array(
'deleteForbidden' => __( 'Formu doldururken silmek yasaktır!', 'UniTimetable' ),
'deleteSharedgroup' => __( 'Bu şube paylaşımını silmek istiyor musunuz?', 'UniTimetable' ),
'sharedgroupDeleted' => __( 'Şube paylaşımı başarıyla silindi!', 'UniTimetable' ),
'sharedgroupNotDeleted' => __( 'Şube paylaşımı silinemedi. Paylaşılan şubelerin eklenen dersler ile bağlantılı olup olmadığını kontrol edin.', 'UniTimetable' ),
'editForbidden' => __( 'Lütfen bir şube paylaşım kuralı seçin!', 'UniTimetable' ),
'editSharedgroup' => __( 'Şube paylaşımını güncelle', 'UniTimetable' ),
'cancel' => __( 'İptal', 'UniTimetable' ),
'yearVal' => __( 'Yıl alanı limitlerin dışında.', 'UniTimetable' ),
'semesterVal' => __( 'Konu düzenlenemedi. Konunun var olup olmadığı kontrol kontrolü edin', 'UniTimetable' ),
'insertSharedgroup' => __( 'Şubeleri paylaştır', 'UniTimetable' ),
'reset' => __( 'Sıfırla', 'UniTimetable' ),
'failAdd' => __( 'Şube paylaşımı eklenemedi. Şube paylaşımının zaten var olup olmadığını kontrol edin.', 'UniTimetable' ),
'successAdd' => __( 'Şube paylaştırıldı!', 'UniTimetable' ),
'failEdit' => __( 'Şube paylaşımı güncellenemedi. Şube paylaşımının zaten var olup olmadığını kontrol edin.', 'UniTimetable' ),
'successEdit' => __( 'Şube paylaşımı başarıyla güncellendi!', 'UniTimetable' ),
));
}
//sharedgroups page
function utt_create_sharedgroups_page()
{
global $wpdb;
global $departments;
$lecturesTable = $wpdb->prefix."utt_lectures";
$groupsTable = $wpdb->prefix."utt_groups";
$subjectsTable = $wpdb->prefix."utt_subjects";
$wpdb->suppress_errors = false;
$wpdb->show_errors = true;
//sharedgroup form
?>
<div class="wrap">
<h2 id="sharedgroupTitle"> <?php _e("Şube paylaştır","UniTimetable"); ?> </h2>
<form action="" name="sharedgroupForm" method="post">
<input type="hidden" name="sgID" id="sgID" value=0 />
<br/><?php _e("Ana Ders:","UniTimetable"); ?><br/>
<select name="groupID" id="groupID" class="dirty">
<option value='0'><?php _e("- seç -","UniTimetable"); ?></option>
<?php
$groups = $wpdb->get_results("SELECT G.groupID, G.groupName, S.subjectID, S.title, S.semester, S.type FROM $subjectsTable S INNER JOIN $groupsTable G ON G.subjectID = S.subjectID;");
foreach($groups as $group)
{
echo "<option value='$group->groupID'>".$departments[$group->semester-1]." » $group->title ($group->type) » $group->groupName</option>";
}
?>
</select>
<br/><?php _e("Diğer Bölümdeki Karşılığı:","UniTimetable"); ?><br/>
<select name="subjectID" id="subjectID" class="dirty">
<option value='0'><?php _e("- seç -","UniTimetable"); ?></option>
<?php
$subjects = $wpdb->get_results("SELECT S.subjectID, S.title, S.semester, S.type FROM $subjectsTable S;");
foreach($subjects as $subject)
{
echo "<option value='$subject->subjectID'>".$departments[$subject->semester-1]." » $subject->title ($subject->type)</option>";
}
echo "{".$wpdb->print_error()."}";
?>
</select>
<br/>
<div id="secondaryButtonContainer">
<input type="submit" value="<?php _e("Paylaştır","UniTimetable"); ?>" id="insert-updateSharedgroup" class="button-primary"/>
<a href='#' class='button-secondary' id="clearSharedgroupForm"><?php _e("Sıfırla","UniTimetable"); ?></a>
</div>
</form>
<!-- place to show messages -->
<div id="messages"></div>
<!-- place to show results table -->
<div id="sharedgroupsResults">
<?php utt_view_sharedgroups(); ?>
</div>
</div>
<?php
}
//show registered sharedgroups
add_action('wp_ajax_utt_view_sharedgroups', 'utt_view_sharedgroups');
function utt_view_sharedgroups(){
global $wpdb;
global $departments, $departmentusers;
$userid = get_current_user_id();
$groupsTable=$wpdb->prefix."utt_groups";
$sharedgroupsTable=$wpdb->prefix."utt_sharedgroups";
$subjectsTable=$wpdb->prefix."utt_subjects";
//$sharedgroups = $wpdb->get_results( "SELECT SG.*, S.*, G.* FROM $sharedgroupsTable SG INNER JOIN $groupsTable G ON G.groupID = SG.groupID INNER JOIN $subjectsTable S ON S.subjectID = SG.subjectID ORDER BY SG.sgID DESC");
$sharedgroups = $wpdb->get_results( "SELECT SG1.sgID sgID, S.semester semester1, S.title title1, G.groupName, T2.semester semester2, T2.title title2 FROM $sharedgroupsTable SG1 INNER JOIN $groupsTable G ON G.groupID = SG1.groupID INNER JOIN $subjectsTable S ON S.subjectID = G.subjectID
INNER JOIN
(SELECT SG2.sgID sgID, S2.semester, S2.title FROM $sharedgroupsTable SG2 INNER JOIN $subjectsTable S2 ON S2.subjectID = SG2.subjectID) T2 ON SG1.sgID=T2.sgID");
/*
*/
?>
<!-- show table with sharedgroups -->
<table class="widefat bold-th">
<thead>
<tr>
<th><?php _e("Ana Ders ve Şube","UniTimetable"); ?></th>
<th><?php _e("Eylemler","UniTimetable"); ?></th>
<th><?php _e("Paylaşıldığı Bölüm ve Ders","UniTimetable"); ?></th>
</tr>
</thead>
<tfoot>
<tr>
<th><?php _e("Ana Ders ve Şube","UniTimetable"); ?></th>
<th><?php _e("Eylemler","UniTimetable"); ?></th>
<th><?php _e("Paylaşıldığı Bölüm ve Ders","UniTimetable"); ?></th>
</tr>
</tfoot>
<tbody>
<?php
//show grey and white records in order to be more recognizable
$bgcolor = 1;
foreach($sharedgroups as $sharedgroup)
{
if($bgcolor == 1)
{
$addClass = "class='grey'";
$bgcolor = 2;
}
else
{
$addClass = "class='white'";
$bgcolor = 1;
}
echo "<tr id='$sharedgroup->sgID' $addClass>
<td><i>{$departments[$sharedgroup->semester1-1]}</i> <br> $sharedgroup->title1 » $sharedgroup->groupName</td>
<td>
<a href='#' onclick='deleteSharedgroup($sharedgroup->sgID);' class='deleteSharedgroup'><img id='edit-delete-icon' src='".plugins_url('icons/delete_icon.png', __FILE__)."'/> ". __("Sil","UniTimetable") ."</a>
</td>
<td><i>{$departments[$sharedgroup->semester2-1]}</i> <br> $sharedgroup->title2</td>
</tr>";
//<a href='#' onclick=\"editSharedgroup($sharedgroup->sgID,'$sharedgroup->sharedgroup');\" class='editSharedgroup'><img id='edit-delete-icon' src='".plugins_url('icons/edit_icon.png', __FILE__)."'/> ". __("Güncelle","UniTimetable") ."</a>
}
?>
</tbody>
</table><?php
die();
}
//ajax response insert-update sharedgroup
add_action('wp_ajax_utt_insert_update_sharedgroup','utt_insert_update_sharedgroup');
function utt_insert_update_sharedgroup(){
global $wpdb;
$userid = get_current_user_id();
/*
$wpdb->suppress_errors = false;
$wpdb->show_errors = true;
*/
//data
$groupID = $_GET['groupID'];
$subjectID = $_GET['subjectID'];
if ($groupID <= 0 || $subjectID <=0)
{
echo 'Bir dersin şubesini ve bu dersin verileceği diğer bölümdeki karşılığını seçmelisiniz.';
die();
}
$sgID=$_GET['sharedgroup_id'];
$sharedgroupsTable=$wpdb->prefix."utt_sharedgroups";
//is insert
if($sgID==0){
$safeSql = $wpdb->prepare("INSERT INTO $sharedgroupsTable (userid,groupID,subjectID) VALUES (%d,%d,%d)",$userid,$groupID,$subjectID);
$success = $wpdb->query($safeSql);
if($success == 1){
//success
echo 1;
}else{
//fail
//echo "{".$wpdb->print_error()."}";
echo 0;
}
//is edit
}/*else{
$safeSql = $wpdb->prepare("UPDATE $sharedgroupsTable SET sharedgroup=%s WHERE sgID=%d ",$sharedgroup,$sgID);
$success = $wpdb->query($safeSql);
if($success == 1){
//success
echo 1;
}else{
//fail
echo 0;
}
}*/
die();
}
//ajax response delete sharedgroup
add_action('wp_ajax_utt_delete_sharedgroup', 'utt_delete_sharedgroup');
function utt_delete_sharedgroup()
{
global $wpdb;
$userid = get_current_user_id();
$sharedgroupsTable=$wpdb->prefix."utt_sharedgroups";
$safeSql = $wpdb->prepare("DELETE FROM $sharedgroupsTable WHERE sgID=%d AND userid=%d",$_GET['sharedgroup_id'],$userid);
$success = $wpdb->query($safeSql);
//if success is 1 then delete succeeded
echo $success;
die();
}
// //ajax response delete sharedgroup
// add_action('wp_ajax_utt_setok_sharedgroup', 'utt_setok_sharedgroup');
// function utt_setok_sharedgroup()
// {
// global $wpdb;
// global $departments, $departmentusers;
// $userid = get_current_user_id();
// $wpdb->suppress_errors = false;
// $wpdb->show_errors = true;
// $sharedgroupsTable=$wpdb->prefix."utt_sharedgroups";
// $subjectsTable=$wpdb->prefix."utt_subjects";
// $sgID = intval($_GET['sharedgroup_id']);
// $subjectID = intval($_GET['subject_id']);
// $val = intval($_GET['val']);
// //echo "".$userid." nolu kullanıcı olarak yapmak istediğiniz: ".$sgID." | ".$subjectID." | ".$val;
// $success = 0;
// $safeSqlSharedgroups = $wpdb->prepare( "SELECT SG.sgID sgID, SH.groupID groupID, SH.subjectID subjectID, S1.title groupIDtitle, S.title subjectIDtitle, S.semester groupIDdepartment FROM $sharedgroupsTable SG LEFT JOIN $subjectsTable S ON SG.groupID=S.subjectID WHERE SG.sgID=%d;",$sgID);
// $sharedgroups = $wpdb->get_results($safeSqlSharedgroups);
// foreach($sharedgroups as $sharedgroup)
// {
// //echo "#".$sharedgroup->sgID." | ".$sharedgroup->subjectIDID." ?= ".$subjectID."#";
// if($sharedgroup->subjectIDID == $subjectID && (IsAdmin() || $userid == $departmentusers[$sharedgroup->subjectIDsemester]))
// {
// $safeSql = $wpdb->prepare("UPDATE $sharedgroupsTable SET subjectIDok=%d WHERE sgID=%d",$val,$sgID);
// $success = $wpdb->query($safeSql);
// }
// else if($sharedgroup->s3ID == $subjectID && (IsAdmin() || $userid == $departmentusers[$sharedgroup->s3semester]))
// {
// $safeSql = $wpdb->prepare("UPDATE $sharedgroupsTable SET s3ok=%d WHERE sgID=%d",$val,$sgID);
// $success = $wpdb->query($safeSql);
// }
// else if($sharedgroup->s4ID == $subjectID && (IsAdmin() || $userid == $departmentusers[$sharedgroup->s4semester]))
// {
// $safeSql = $wpdb->prepare("UPDATE $sharedgroupsTable SET s4ok=%d WHERE sgID=%d",$val,$sgID);
// $success = $wpdb->query($safeSql);
// }
// else if($sharedgroup->s5ID == $subjectID && (IsAdmin() || $userid == $departmentusers[$sharedgroup->s5semester]))
// {
// $safeSql = $wpdb->prepare("UPDATE $sharedgroupsTable SET s5ok=%d WHERE sgID=%d",$val,$sgID);
// $success = $wpdb->query($safeSql);
// }
// }
// //echo "{".$wpdb->print_error()."}";
// if($success == 0)
// {
// echo "Bu işlemi yapma yetkiniz bulunmamaktadır.";
// }
// else
// {
// if($val==1)
// echo "Bu şube paylaşımını onayladınız.";
// else
// echo "Bu şube paylaşımının onayını kaldırdınız.";
// }
// /*
// $sharedgroupsTable=$wpdb->prefix."utt_sharedgroups";
// $safeSql = $wpdb->prepare("DELETE FROM $sharedgroupsTable WHERE sgID=%d AND userid=%d",$_GET['sharedgroup_id'],$userid);
// $success = $wpdb->query($safeSql);*/
// //if success is 1 then delete succeeded
// //echo $success;
// die();
// }
?>