-
Notifications
You must be signed in to change notification settings - Fork 3
/
functions.php
299 lines (265 loc) · 9.51 KB
/
functions.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
<?php
/*
* This function create By Jignesh Patel
* Function requested by Ajax
*/
if(isset($_REQUEST['fun_type']) && !empty($_REQUEST['fun_type'])){
switch($_REQUEST['fun_type']){
case 'get_calender_full':
get_calender_full($_REQUEST['year'],$_REQUEST['month']);
break;
case 'get_events_information':
get_events_information($_REQUEST['date']);
break;
//For Add Event with date wise.
case 'add_event_information':
add_event_information($_REQUEST['date'],$_REQUEST['title']);
break;
default:
break;
}
}
/*
* Get Full calendar in html
*/
function get_calender_full($year = '',$month = '')
{
$date_Year = ($year != '')?$year:date("Y");
$date_Month = ($month != '')?$month:date("m");
$date = $date_Year.'-'.$date_Month.'-01';
$current_Month_First_Day = date("N",strtotime($date));
$total_Days_ofMonth = cal_days_in_month(CAL_GREGORIAN,$date_Month,$date_Year);
$total_Days_ofMonthDisplay = ($current_Month_First_Day == 7)?($total_Days_ofMonth):($total_Days_ofMonth + $current_Month_First_Day);
$boxDisplay = ($total_Days_ofMonthDisplay <= 35)?35:42;
?>
<div id="calender_section">
<h2>
<a href="javascript:void(0);" onclick="get_calendar_data('calendar_div','<?php echo date("Y",strtotime($date.' - 1 Month')); ?>','<?php echo date("m",strtotime($date.' - 1 Month')); ?>');"><</a>
<select name="month_dropdown" class="month_dropdown dropdown"><?php echo get_all_months__of_year($date_Month); ?></select>
<select name="year_dropdown" class="year_dropdown dropdown"><?php echo get_year($date_Year); ?></select>
<a href="javascript:void(0);" onclick="get_calendar_data('calendar_div','<?php echo date("Y",strtotime($date.' + 1 Month')); ?>','<?php echo date("m",strtotime($date.' + 1 Month')); ?>');">></a>
</h2>
<!-- event_list is used for view event with popup -->
<div id="event_list" class="modal"></div>
<!-- End of event list popup -->
<!--Below Code for Event Add-->
<!-- Popup div start here -->
<div id="event_add" class="modal">
<div class="modal-content">
<span class="close"><a href="#" onclick="close_popup('event_add')">×</a></span>
<p>Add Event on <span id="eventDateView"></span></p>
<p><b>Event Title: </b><input type="text" id="eventTitle" value=""/></p>
<input type="hidden" id="eventDate" value=""/>
<input type="button" id="add_event_informationBtn" value="Add"/>
</div>
</div>
<!-- Popup hmmt end. -->
<div id="calender_section_top">
<ul>
<li>SUN</li>
<li>MON</li>
<li>TUE</li>
<li>WED</li>
<li>THU</li>
<li>FRI</li>
<li>SAT</li>
</ul>
</div>
<div id="calender_section_bot">
<ul>
<?php
// this is for create calendra and view add event and view event and number of Events
$dayCount = 1;
for($cb=1;$cb<=$boxDisplay;$cb++){
if(($cb >= $current_Month_First_Day+1 || $current_Month_First_Day == 7) && $cb <= ($total_Days_ofMonthDisplay)){
// Below javascript code for get current date
$currentDate = $date_Year.'-'.$date_Month.'-'.$dayCount;
$eventNum = 0;
// Below line for including file of database connection file
include 'connection.php';
// Below query useing for getting number of events in current date
$result = $db->query("SELECT title FROM events WHERE date = '".$currentDate."' AND status = 1");
$eventNum = $result->num_rows;
//Define date cell color
if(strtotime($currentDate) == strtotime(date("Y-m-d"))){
echo '<li date="'.$currentDate.'" class="grey date_cell">';
}elseif($eventNum > 0){
echo '<li date="'.$currentDate.'" class="light_sky date_cell">';
}else{
echo '<li date="'.$currentDate.'" class="date_cell">';
}
//Date cell
echo '<span>';
echo '['.$dayCount.']';
echo '</span>';
//Hover event popup
echo '<div id="date_popup_'.$currentDate.'" class="date_popup_wrap none">';
echo '<div class="date_window">';
echo '<div class="popup_event">Events ('.$eventNum.')</div>';
echo ($eventNum > 0)?'<a href="javascript:;" onclick="get_events_information(\''.$currentDate.'\');">View Events</a><br/>':'';
//For Add Event
echo '<a href="javascript:;" onclick="add_event_information(\''.$currentDate.'\');">Add Event</a>';
echo '</div></div>';
echo '</li>';
$dayCount++;
?>
<?php }else{ ?>
<li><span> </span></li>
<?php } } ?>
</ul>
</div>
</div>
<script type="text/javascript">
// ajax call to get event detail from database.
function get_calendar_data(target_div,year,month){
$.ajax({
type:'POST',
url:'functions.php',
data:'fun_type=get_calender_full&year='+year+'&month='+month,
success:function(html){
$('#'+target_div).html(html);
}
});
}
function get_events_information(date){
$.ajax({
type:'POST',
url:'functions.php',
data:'fun_type=get_events_information&date='+date,
success:function(html){
$('#event_list').html(html);
$('#event_add').slideUp('slow');
$('#event_list').slideDown('slow');
}
});
}
/*
* function name add_event_information
* Description :- Add Event inforation as per date wise
* parameter :- date
*/
function add_event_information(date){
$('#eventDate').val(date);
$('#eventDateView').html(date);
$('#event_list').slideUp('slow');
$('#event_add').slideDown('slow');
}
/*
* below code used for save event information into databse. and set message event created successfully.
*/
$(document).ready(function(){
$('#add_event_informationBtn').on('click',function(){
var date = $('#eventDate').val();
var title = $('#eventTitle').val();
$.ajax({
type:'POST',
url:'functions.php',
data:'fun_type=add_event_information&date='+date+'&title='+title,
success:function(msg){
if(msg == 'ok'){
var dateSplit = date.split("-");
$('#eventTitle').val('');
alert('Event Created.');
get_calendar_data('calendar_div',dateSplit[0],dateSplit[1]);
}else{
alert('Sorry some issues please try again later.');
}
}
});
});
});
$(document).ready(function(){
$('.date_cell').mouseenter(function(){
date = $(this).attr('date');
$(".date_popup_wrap").fadeOut();
$("#date_popup_"+date).fadeIn();
});
$('.date_cell').mouseleave(function(){
$(".date_popup_wrap").fadeOut();
});
$('.month_dropdown').on('change',function(){
get_calendar_data('calendar_div',$('.year_dropdown').val(),$('.month_dropdown').val());
});
$('.year_dropdown').on('change',function(){
get_calendar_data('calendar_div',$('.year_dropdown').val(),$('.month_dropdown').val());
});
$(document).click(function(){
$('#event_list').slideUp('slow');
});
});
// Closed popup string
function close_popup(event_id)
{
$('#'+event_id).css('display','none');
}
</script>
<?php
}
/*
* below function with get all month list
* optional parameter >> $selected
*/
function get_all_months__of_year($selected = ''){
$options = '';
for($i=1;$i<=12;$i++)
{
$value = ($i < 01)?'0'.$i:$i;
$selectedOpt = ($value == $selected)?'selected':'';
$options .= '<option value="'.$value.'" '.$selectedOpt.' >'.date("F", mktime(0, 0, 0, $i+1, 0, 0)).'</option>';
}
return $options;
}
/*
* below function with get all year list
* optional parameter >> $selected
*/
function get_year($selected = ''){
$options = '';
for($i=2015;$i<=2025;$i++)
{
$selectedOpt = ($i == $selected)?'selected':'';
$options .= '<option value="'.$i.'" '.$selectedOpt.' >'.$i.'</option>';
}
return $options;
}
/********************************************
* below function used for display event as per date
* optional parameter is date.
*******************************************/
function get_events_information($date = ''){
//below line for including file of database connection file
include 'connection.php';
$eventListHTML = '';
$date = $date?$date:date("Y-m-d");
//Get events based on the current date
$result = $db->query("SELECT title FROM events WHERE date = '".$date."' AND status = 1");
if($result->num_rows > 0){
$eventListHTML .= '<div class="modal-content">';
$eventListHTML .= '<span class="close"><a href="#" onclick="close_popup("event_list")">×</a></span>';
$eventListHTML .= '<h2>Events on '.date("l, d M Y",strtotime($date)).'</h2>';
$eventListHTML .= '<ul>';
while($row = $result->fetch_assoc()){
$eventListHTML .= '<li>'.$row['title'].'</li>';
}
$eventListHTML .= '</ul>';
$eventListHTML .= '</div>';
}
echo $eventListHTML;
}
/**********************************************************
* below function is used for add event in paraticular date
* parameter is >>> date , title
**********************************************************/
function add_event_information($date,$title){
//below line for including file of database connection file
include 'connection.php';
$currentDate = date("Y-m-d H:i:s");
//Insert the event data into database
$insert = $db->query("INSERT INTO events (title,date,created,modified) VALUES ('".$title."','".$date."','".$currentDate."','".$currentDate."')");
if($insert){
echo 'ok';
}else{
echo 'err';
}
}
?>