See Events in calendar, using PHP and Javascript, -
in matter, have problem when site online(live), works locally when online (live) not show events
<script type="text/javascript" language="javascript"> events = new array( <? php $get_event = $db - > execute("select * events fromdate>= date(now()) , removed='n'"); // $get_event=$db->execute("select * events fromdate>='".$_session['session_start_date_s_front']."' , removed='n'"); $ttl_event = $get_event - > recordcount(); $gp = 1; while (!$get_event - > eof) { $xx = dates_range($get_event - > fields['fromdate'], $get_event - > fields['todate']); $ttl_dte = count($xx) - 1; ($i = 0; $i < count($xx); $i++) { $d_e = explode('-', $xx[$i]); if ($gp == $ttl_event && $i == $ttl_dte) { ?> ["d", "<?php echo $d_e[1]?>", "<?php echo $d_e[2]?>", "<?php echo $d_e[0]?>", "1:00 am", "12:59 pm", "<?php echo addslashes($get_event->fields['event'])?>", ""] <? php } else { ?> ["d", "<?php echo $d_e[1]?>", "<?php echo $d_e[2]?>", "<?php echo $d_e[0]?>", "1:00 am", "12:59 pm", "<?php echo addslashes($get_event->fields['event'])?>", ""], <? php } } $gp++; $get_event - > movenext(); } ?>
create database table create table `events` ( `id` int(11) not null auto_increment, `title` varchar(255) collate utf8_unicode_ci not null, `date` date not null, `created` datetime not null, `modified` datetime not null, `status` tinyint(1) not null default '1' comment '1=active, 0=block', primary key (`id`) ) engine=innodb default charset=utf8 collate=utf8_unicode_ci;
/* * function requested ajax */
if(isset($_post['func']) && !empty($_post['func'])){ switch($_post['func']){ case 'getcalender': getcalender($_post['year'],$_post['month']); break; case 'getevents': getevents($_post['date']); break; default: break; } } /* * calendar full html */ function getcalender($year = '',$month = '') { $dateyear = ($year != '')?$year:date("y"); $datemonth = ($month != '')?$month:date("m"); $date = $dateyear.'-'.$datemonth.'-01'; $currentmonthfirstday = date("n",strtotime($date)); $totaldaysofmonth = cal_days_in_month(cal_gregorian,$datemonth,$dateyear); $totaldaysofmonthdisplay = ($currentmonthfirstday == 7)?($totaldaysofmonth):($totaldaysofmonth + $currentmonthfirstday); $boxdisplay = ($totaldaysofmonthdisplay <= 35)?35:42; ?> <div id="calender_section"> <h2> <a href="javascript:void(0);" onclick="getcalendar('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 getallmonths($datemonth); ?></select> <select name="year_dropdown" class="year_dropdown dropdown"><?php echo getyearlist($dateyear); ?></select> <a href="javascript:void(0);" onclick="getcalendar('calendar_div','<?php echo date("y",strtotime($date.' + 1 month')); ?>','<?php echo date("m",strtotime($date.' + 1 month')); ?>');">>></a> </h2> <div id="event_list" class="none"></div> <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 $daycount = 1; for($cb=1;$cb<=$boxdisplay;$cb++){ if(($cb >= $currentmonthfirstday+1 || $currentmonthfirstday == 7) && $cb <= ($totaldaysofmonthdisplay)){ //current date $currentdate = $dateyear.'-'.$datemonth.'-'.$daycount; $eventnum = 0; //include db configuration file include 'dbconfig.php'; //get number of events based on current date $result = $db->query("select title events date = '".$currentdate."' , 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="getevents(\''.$currentdate.'\');">view events</a>':''; echo '</div></div>'; echo '</li>'; $daycount++; ?> <?php }else{ ?> <li><span> </span></li> <?php } } ?> </ul> </div> </div> <script type="text/javascript"> function getcalendar(target_div,year,month){ $.ajax({ type:'post', url:'functions.php', data:'func=getcalender&year='+year+'&month='+month, success:function(html){ $('#'+target_div).html(html); } }); } function getevents(date){ $.ajax({ type:'post', url:'functions.php', data:'func=getevents&date='+date, success:function(html){ $('#event_list').html(html); $('#event_list').slidedown('slow'); } }); } function addevent(date){ $.ajax({ type:'post', url:'functions.php', data:'func=addevent&date='+date, success:function(html){ $('#event_list').html(html); $('#event_list').slidedown('slow'); } }); } $(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(){ getcalendar('calendar_div',$('.year_dropdown').val(),$('.month_dropdown').val()); }); $('.year_dropdown').on('change',function(){ getcalendar('calendar_div',$('.year_dropdown').val(),$('.month_dropdown').val()); }); $(document).click(function(){ $('#event_list').slideup('slow'); }); }); </script> <?php } /* * months options list. */ function getallmonths($selected = ''){ $options = ''; for($i=1;$i<=12;$i++) { $value = ($i < 10)?'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; } /* * years options list. */ function getyearlist($selected = ''){ $options = ''; for($i=2015;$i<=2025;$i++) { $selectedopt = ($i == $selected)?'selected':''; $options .= '<option value="'.$i.'" '.$selectedopt.' >'.$i.'</option>'; } return $options; } /* * events date */ function getevents($date = ''){ //include db configuration file include 'dbconfig.php'; $eventlisthtml = ''; $date = $date?$date:date("y-m-d"); //get events based on current date $result = $db->query("select title events date = '".$date."' , status = 1"); if($result->num_rows > 0){ $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>'; } echo $eventlisthtml; } ?>
//in index.php
<?php //include event calendar functions file include_once('functions.php'); ?> <!doctype html> <html lang="en-us"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>php event calendar codexworld</title> <!-- include stylesheet --> <link type="text/css" rel="stylesheet" href="style.css"/> <!-- include jquery library --> <script src="jquery.min.js"></script> </head> <body> <!-- display event calendar --> <div id="calendar_div"> <?php echo getcalender(); ?> </div> </body> </html>
Comments
Post a Comment