-
Notifications
You must be signed in to change notification settings - Fork 0
/
classroomsFunctions.php
208 lines (191 loc) · 8.96 KB
/
classroomsFunctions.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
<?php
//include js
function utt_classroom_scripts(){
//load classroomScripts
wp_enqueue_script( 'classroomScripts', plugins_url('js/classroomScripts.js?v=1000', __FILE__) );
//localize classroomScripts
wp_localize_script( 'classroomScripts', 'classroomStrings', array(
'deleteForbidden' => __( 'Formu doldururken silmek yasaktır!', 'UniTimetable' ),
'deleteClassroom' => __( 'Bu şubeyi silmek istediğinize emin misiniz?', 'UniTimetable' ),
'classroomDeleted' => __( 'Sınıf başarıyla silindi!', 'UniTimetable' ),
'classroomNotDeleted' => __( 'Sınıf silinemedi. Sınıfın bir Ders veya Etkinlik tarafından kullanılıp kullanılmadığını kontrol edin.', 'UniTimetable' ),
'editForbidden' => __( 'Form doldurulurken düzenleme yapmak yasaktır!', 'UniTimetable' ),
'editClassroom' => __( 'Sınıf güncelle', 'UniTimetable' ),
'cancel' => __( 'İptal', 'UniTimetable' ),
'nameVal' => __( 'Sınıf adı zorunludur. Lütfen özel karakter kullanmaktan kaçının.', 'UniTimetable' ),
'typeVal' => __( 'Lütfen sınıf tipi seçiniz.', 'UniTimetable' ),
'insertClassroom' => __( 'Sınıf Ekle.', 'UniTimetable' ),
'reset' => __( 'Sıfırla', 'UniTimetable' ),
'failAdd' => __( 'Sınıf eklenemedi. Sınıfın var olup olmadığını kontrol edin.', 'UniTimetable' ),
'successAdd' => __( 'Sınıf başarıyla eklendi!', 'UniTimetable' ),
'failEdit' => __( 'Sınıf düzenlenemedi. Sınıfın var olup olmadığını kontrol edin.', 'UniTimetable' ),
'successEdit' => __( 'Sınıf başarıyla güncellendi!', 'UniTimetable' ),
));
}
//classroom page
function utt_create_classrooms_page(){
//classroom form
?>
<div class="wrap">
<h2 id="classroomTitle"> <?php _e("Sınıf ekle","UniTimetable"); ?> </h2>
<form action="" name="classroomForm" method="post">
<input type="hidden" name="classroomID" id="classroomID" value=0 />
<?php _e("Sınıf ismi:","UniTimetable"); ?><br/>
<input type="text" name="classroomName" id="classroomName" class="dirty" value="" placeholder="<?php _e("","UniTimetable"); ?>"/>
<br/>
<?php _e("Ders türü:","UniTimetable"); ?><br/>
<select name="classroomType" id="classroomType" class="dirty">
<option value="0"><?php _e("- seç -","UniTimetable"); ?></option>
<option value="Düz"><?php _e("Düz","UniTimetable"); ?></option>
<option value="Laboratuvar"><?php _e("Laboratuvar","UniTimetable"); ?></option>
<option value="Amfi"><?php _e("Amfi","UniTimetable"); ?></option>
<option value="Toplantı Salonu"><?php _e("Toplantı Salonu","UniTimetable"); ?></option>
<option value="Salon"><?php _e("Salon","UniTimetable"); ?></option>
</select>
<br/>
<?php _e("Sınıf kapasitesi:","UniTimetable"); ?><br/>
<input type="text" name="classroomCapacity" id="classroomCapacity" class="dirty" value="" placeholder="<?php _e("","UniTimetable"); ?>"/>
<br/>
<?php _e("Aktiflik:","UniTimetable"); ?><br/>
<select name="classroomType" id="classroomAvailable" class="dirty">
<option value="1"><?php _e("Aktif","UniTimetable"); ?></option>
<option value="0"><?php _e("Pasif","UniTimetable"); ?></option>
</select>
<br/>
<div id="secondaryButtonContainer">
<input type="submit" value="<?php _e("Ekle","UniTimetable"); ?>" id="insert-updateClassroom" class="button-primary"/>
<a href='#' class='button-secondary' id="clearClassroomForm"><?php _e("Sıfırla","UniTimetable"); ?></a>
</div>
</form>
<!-- place to put messages -->
<div id="messages"></div>
<!-- place to put table with classroom results -->
<div id="classroomsResults">
<?php utt_view_classrooms(); ?>
</div>
<?php
}
//ajax response view classrooms
add_action('wp_ajax_utt_view_classrooms','utt_view_classrooms');
function utt_view_classrooms(){
global $wpdb;
//define classrooms table
$classroomsTable=$wpdb->prefix."utt_classrooms";
//select all classrooms
$classrooms = $wpdb->get_results( "SELECT * FROM $classroomsTable ORDER BY name");
?>
<!-- show classrooms table -->
<table class="widefat bold-th">
<thead>
<tr>
<th>ID</th>
<th><?php _e("İsim","UniTimetable"); ?></th>
<th><?php _e("Tip","UniTimetable"); ?></th>
<th><?php _e("Kapasite","UniTimetable"); ?></th>
<th><?php _e("Aktiflik Durumu","UniTimetable"); ?></th>
<th><?php _e("Hareketler","UniTimetable"); ?></th>
</tr>
</thead>
<tfoot>
<tr>
<th>ID</th>
<th><?php _e("İsim","UniTimetable"); ?></th>
<th><?php _e("Tip","UniTimetable"); ?></th>
<th><?php _e("Kapasite","UniTimetable"); ?></th>
<th><?php _e("Aktiflik Durumu","UniTimetable"); ?></th>
<th><?php _e("Hareketler","UniTimetable"); ?></th>
</tr>
</tfoot>
<tbody>
<?php
//show grey and white records in order to be more recognizable
$bgcolor = 1;
foreach($classrooms as $classroom)
{
if($bgcolor == 1){
$addClass = "class='grey'";
$bgcolor = 2;
}else{
$addClass = "class='white'";
$bgcolor = 1;
}
/*if($classroom->type == "Lecture"){
$type = __("Teori","UniTimetable");
}else{
$type = __("Laboratuvar","UniTimetable");
}*/
$type = __("".$classroom->type,"UniTimetable");
$classAvailableStatue = "-";
if($classroom->is_available == "1")
{
$classAvailableStatue = __("<b>Aktif</b>","UniTimetable");
}
else
{
$classAvailableStatue = __("<i>Pasif</i>","UniTimetable");
}
//a record
echo "<tr id='$classroom->classroomID' $addClass>
<td>$classroom->classroomID</td>
<td>$classroom->name</td>
<td>$type</td>
<td>$classroom->capacity</td>
<td>$classAvailableStatue</td>
<td><a href='#' onclick='deleteClassroom($classroom->classroomID);' class='deleteClassroom'><img id='edit-delete-icon' src='".plugins_url('icons/delete_icon.png', __FILE__)."'/> ".__("Sil","UniTimetable")."</a>
<a href='#' onclick=\"editClassroom($classroom->classroomID,'$classroom->name','$classroom->type',$classroom->capacity,$classroom->is_available);\" class='editClassroom'><img id='edit-delete-icon' src='".plugins_url('icons/edit_icon.png', __FILE__)."'/> ".__("Güncelle","UniTimetable")."</a></td></tr>";
}
?>
</tbody>
</table>
<?php
die();
}
//ajax response insert-update classroom
add_action('wp_ajax_utt_insert_update_classroom','utt_insert_update_classroom');
function utt_insert_update_classroom(){
global $wpdb;
//data to insert or update
$classroomID=$_GET['classroom_id'];
$classroomName=$_GET['classroom_name'];
$classroomType=$_GET['classroom_type'];
$classroomCapacity=$_GET['classroom_capacity'];
$classroomAvailable=$_GET['classroom_available'];
//define classrooms table
$classroomsTable=$wpdb->prefix."utt_classrooms";
//if classroomID is 0, so it is insert
if($classroomID==0){
$safeSql = $wpdb->prepare("INSERT INTO $classroomsTable (name, type, capacity) VALUES (%s,%s,%d)",$classroomName,$classroomType,$classroomCapacity);
$success = $wpdb->query($safeSql);
//if insert succeeded echo 1
if($success == 1){
echo 1;
//else echo 0
}else{
echo 0;
}
//if classroomID is not 0, so it is edit
}else{
$safeSql = $wpdb->prepare("UPDATE $classroomsTable SET name=%s, type=%s, capacity=%d, is_available=%d WHERE classroomID=%d ",$classroomName,$classroomType,$classroomCapacity,$classroomAvailable,$classroomID);
$success = $wpdb->query($safeSql);
//if update succeeded echo 1
if($success == 1){
echo 1;
//else echo 0
}else{
echo 0;
}
}
die();
}
//ajax response delete classroom
add_action('wp_ajax_utt_delete_classroom', 'utt_delete_classroom');
function utt_delete_classroom(){
global $wpdb;
$classroomsTable=$wpdb->prefix."utt_classrooms";
$safeSql = $wpdb->prepare("DELETE FROM $classroomsTable WHERE classroomID=%d",$_GET['classroom_id']);
$success = $wpdb->query($safeSql);
//if delete succeeds it echoes 1
echo $success;
die();
}
?>