Announcements

Spam Blaster Implemented
by NetriX - 4 months ago
The New PHP-Fusion USA
by NetriX - 8 months ago

Latest Posts

View Thread

Who is here? 1 guest(s)
 Print Thread
Ajax Calendar Panel
Driv3r
Hi everyone!
I?m trying to modify an infusion called Event Management System, and make the calendar panel of it ajax based, so it won?t reload the whole page when someone changes the date.
Sadly I?m not so good at PHP, and my Ajax knowledge is equal with zero. :D
Maybe there's not much problem with the PHP part, but I don?t know how to make ajax to post the values correctly.
The events_management_system_panel.php (the ajax code is in this):
Download source  PHP
  1. <?php
  2. /*-------------------------------------------------------+
  3. | PHP-Fusion Content Management System
  4. | Copyright ? 2002 - 2011 Nick Jones
  5. | http://www.php-fusion.co.uk/
  6. +--------------------------------------------------------+
  7. | Infusion: Event Management System
  8. | Filename: events_management_system_panel.php
  9. | Developer: Ankur Thakur
  10. | Author: PHP-Fusion Mods UK
  11. | Version: 1.00
  12. | Web: http://www.phpfusionmods.co.uk
  13. +--------------------------------------------------------+
  14. | This program is released as free software under the
  15. | Affero GPL license. You can redistribute it and/or
  16. | modify it under the terms of this license which you
  17. | can read by viewing the included agpl.txt or online
  18. | at http://www.gnu.org/licenses/agpl.html. Removal of this
  19. | copyright header is strictly prohibited without
  20. | written permission from the original author(s).
  21. +--------------------------------------------------------*/
  22. if (!defined("IN_FUSION")) { die("Access Denied"); }
  23.  
  24. // Check If the Infusion is Infused or Not. Done to Minimize Error Logs
  25. $infused_or_not = dbquery("SELECT * FROM ".DB_INFUSIONS. " WHERE inf_folder='events_management_system_panel'");
  26.  
  27. if (dbrows($infused_or_not) > 0) {
  28.  
  29. // Including for Infusion Functions
  30. include_once INCLUDES."infusions_include.php";
  31.  
  32. // Database Settings
  33. // Fetching Database Settings
  34. $emssettings = array();
  35. $emssettings = get_settings("events_management_system_panel");
  36.  
  37. // Defining a Constant for the Infusion directory
  38. if (!defined("EMSDIR")) {
  39. define("EMSDIR", INFUSIONS."events_management_system_panel/");
  40. }
  41.  
  42. // Including Locales
  43. if (file_exists(EMSDIR."locale/".$settings['locale'].".php")) {
  44.     include EMSDIR."locale/".$settings['locale'].".php";
  45. } else {
  46.     include EMSDIR."locale/English.php";
  47. }
  48.  
  49. include_once EMSDIR."infusion_db.php";
  50. include_once EMSDIR."includes/functions.php";
  51.  
  52. // CSS
  53. add_to_head("<link rel='stylesheet' href='".EMSDIR."includes/panel-styles.css' type='text/css' media='all' />");
  54. add_to_head("<style type='text/css'>
  55. .panel-date, .panel-date a
  56. {
  57.     background-color: #".$emssettings['ems_bgcolor_dates'].";
  58.     color: #".$emssettings['ems_color_dates'].";
  59. }
  60. .panel-daynames
  61. {
  62.     background-color: #".$emssettings['ems_bgcolor_days'].";
  63.     color: #".$emssettings['ems_color_days'].";
  64. }
  65. </style>");
  66.  
  67. // To Remove Duplicate Adding of Header files on page calendar.php
  68. if (FUSION_SELF != "calendar.php")
  69. {
  70. add_to_head("<script src='".EMSDIR."includes/jQuery.bubbletip-1.0.6.js' type='text/javascript'></script>
  71. <link href='".EMSDIR."includes/bubbletip/bubbletip.css' rel='stylesheet' type='text/css' />
  72. <!--[if IE]>
  73. <link href='".EMSDIR."includes/bubbletip/bubbletip-IE.css' rel='stylesheet' type='text/css' />
  74. <![endif]-->");
  75.  
  76. // Background Colors for Dates
  77. add_to_head("<style type='text/css'>
  78. .current-day, .current-day a
  79. {
  80.     background-color: #".$emssettings['ems_bgcolor_currentdate'].";
  81.     color: #".$emssettings['ems_color_currentdate'].";
  82. }
  83. .has-events, .has-events a
  84. {
  85.     background-color: #".$emssettings['ems_bgcolor_eventdate'].";
  86.     color: #".$emssettings['ems_color_eventdate'].";
  87. }
  88. .c-daynames
  89. {
  90.     background-color: #".$emssettings['ems_bgcolor_days'].";
  91.     color: #".$emssettings['ems_color_days'].";
  92. }
  93. </style>");
  94. }
  95.  
  96. add_to_head("<script type='text/javascript'>
  97. /* Ajax Calender Panel by bartek124
  98.  * http://www.bartek124.net
  99.  * based on Calender Panel by Nick Jones (Digitanium)
  100.  * http://www.php-fusion.co.uk
  101.  */
  102. /* <![CDATA[ */ 
  103. $(document).ready(function() {
  104.     var cur_month = $('#switch-calendar input[name=\"cur_month\"]').val();
  105.     var cur_year = $('#switch-calendar input[name=\"cur_year\"]').val();
  106.     
  107.     $('#switch-calendar input[name=\"prev_month\"]').click(function(event) {
  108.         $('#switch-calendar table').stop().fadeTo('fast', 0.001, function() {
  109.             $.post('".INFUSIONS."events_management_system_panel/panel.php', {'prev_month': true, 'cur_month': cur_month, 'cur_year': cur_year}, function(data) {
  110.                 $('#switch-calendar table').html(data);
  111.                 cur_month = $('#switch-calendar input[name=\"cur_month\"]').val();
  112.                 cur_year = $('#switch-calendar input[name=\"cur_year\"]').val();
  113.                 $('#switch-calendar table').stop().fadeTo('fast', 1.0);
  114.             });
  115.         });
  116.         event.preventDefault();
  117.     });
  118.     
  119.     $('#switch-calendar input[name=\"next_month\"]').click(function(event) {
  120.         $('#switch-calendar table').stop().fadeTo('fast', 0.001, function() {
  121.             $.post('".INFUSIONS."events_management_system_panel/panel.php', {'next_month': true, 'cur_month': cur_month, 'cur_year': cur_year}, function(data) {
  122.                 $('#switch-calendar table').html(data);
  123.                 cur_month = $('#switch-calendar input[name=\"cur_month\"]').val();
  124.                 cur_year = $('#switch-calendar input[name=\"cur_year\"]').val();
  125.                 $('#switch-calendar table').stop().fadeTo('fast', 1.0);
  126.             });
  127.         });
  128.         event.preventDefault();
  129.     });
  130. });
  131. /* ]]> */ 
  132. </script>");
  133.  
  134. // Panel Title
  135. openside($locale['calendar_title']);
  136.  
  137. // Title and Month changer Links
  138. $internal = true;
  139. echo "<div class='panel-month' align='center' style='clear: both; display: block; width: 100%;'>\n";
  140. echo "<form id='switch-calendar' name='switch-calendar' method='post' action='".FUSION_SELF.(FUSION_QUERY ? "?".FUSION_QUERY : "")."'>\n";
  141. echo "<input type='submit' name='prev_month' value='<' style='background: transparent; border: 0; color: #fff; padding: 5px; float:left;' />\n";
  142. /*echo $year."&nbsp;".$mon."\n";*/
  143. echo "<input type='submit' name='next_month' value='>' style='background: transparent; border: 0; color: #fff; padding: 5px; float:right;' />\n";
  144. echo "<table width='100%' cellpadding='0' cellspacing='0'>\n";
  145. include INFUSIONS."events_management_system_panel/panel.php";
  146. echo "</table>\n";
  147. echo "</form>\n";
  148. echo "</div>\n";
  149.  
  150. closeside();
  151.  
  152. // Add Javascript to Header
  153. if ($js_code_to_add != "")
  154. {
  155. add_to_head("<script type='text/javascript'>
  156. $(window).bind('load', function() {
  157. ".$js_code_to_add."});
  158. </script>");
  159. }
  160.  
  161. }
  162.  
  163. ?>


The additional panel.php I made:
Download source  PHP
  1. <?php
  2. if (!isset($internal)) {
  3. require_once "../../maincore.php";
  4. // Defining a Constant for the Infusion directory
  5. if (!defined("EMSDIR")) {
  6. define("EMSDIR", INFUSIONS."events_management_system_panel/");
  7. }
  8.  
  9. // Including for Infusion Functions
  10. include_once INCLUDES."infusions_include.php";
  11. include_once EMSDIR."infusion_db.php";
  12. include_once EMSDIR."includes/functions.php";
  13.  
  14. // Database Settings
  15. // Fetching Database Settings
  16. $emssettings = array();
  17. $emssettings = get_settings("events_management_system_panel");
  18.  
  19. // Defining a Constant for the Infusion directory
  20. if (!defined("EMSDIR")) {
  21. define("EMSDIR", INFUSIONS."events_management_system_panel/");
  22. }
  23.  
  24. // Including Locales
  25. if (file_exists(EMSDIR."locale/".$settings['locale'].".php")) {
  26.     include EMSDIR."locale/".$settings['locale'].".php";
  27. } else {
  28.     include EMSDIR."locale/English.php";
  29. }
  30.  
  31. }
  32.  
  33. // Set the Month and Year to Current Time as Default
  34. $month = date("n");
  35. $year = date("Y");
  36.  
  37. // If User Requests for specific Month and Year, then Set values for it.
  38. if (isset($_POST['prev_month']) && isNum($_POST['curr_month']) && ($_POST['curr_month'] <= 12))
  39. {
  40.     $month = $_POST['curr_month']-1;
  41.     $year = $_POST['curr_year'];
  42. }
  43. if (isset($_POST['next_month']) && isNum($_POST['curr_month']) && ($_POST['curr_month'] <= 12))
  44. {
  45.     $month = $_POST['curr_month']+1;
  46.     $year = $_POST['curr_year'];
  47. }
  48.  
  49. // Variables for Previous and Next Link
  50. // Set to Current Year by Default
  51. $previous_year = $year;
  52. $next_year = $year;
  53.  
  54. // Variables for Previous and Next Month
  55. $previous_month = $month-1;
  56. $next_month = $month+1;
  57.  
  58. // If Current Month is 1, i.e, January, then Previous month is 0.
  59. // So we must set it to 12, i.e, December of Previous year
  60. if ($previous_month == 0)
  61. {
  62.     $previous_month = 12;
  63.     $previous_year = $year-1;
  64. }
  65.  
  66. // If Current Month is 12, i.e, December, then Next month is 13.
  67. // So we must set it to 1, i.e, January of Next year
  68. if ($next_month == 13)
  69. {
  70.     $next_month = 1;
  71.     $next_year = $year+1;
  72. }
  73.  
  74. // Variables for Current Date, Month and Year
  75. $this_date = date("j");    // Today's Date in Numeric
  76. $this_month = date("m");    // This Month
  77. $this_year = date("Y");    // This Year
  78.  
  79. $start = mktime(0, 0, 0, $month, 1, $year);    // Make Date of the Requested month and year
  80. $mon = date("F", $start);    // Month
  81. $year = date("Y", $start);    // Year
  82. $day_of_week = date("N", $start);    // Day of Week : Monday=1, Tuesday=2, etc
  83. $days_in_month = date("t", $start);    // Total Number of Days in Month
  84.  
  85. echo "<input type='hidden' name='curr_month' value='".$month."' />\n";
  86. echo "<input type='hidden' name='curr_year' value='".$year."' />\n";
  87. echo "<tr>\n";
  88. echo "\t<td class='panel-daynames'>".substr($locale['day_mon'], 0, 1)."</td>\n";
  89. echo "\t<td class='panel-daynames'>".substr($locale['day_tue'], 0, 1)."</td>\n";
  90. echo "\t<td class='panel-daynames'>".substr($locale['day_wed'], 0, 3)."</td>\n";
  91. echo "\t<td class='panel-daynames'>".substr($locale['day_thu'], 0, 2)."</td>\n";
  92. echo "\t<td class='panel-daynames'>".substr($locale['day_fri'], 0, 1)."</td>\n";
  93. echo "\t<td class='panel-daynames'>".substr($locale['day_sat'], 0, 3)."</td>\n";
  94. echo "\t<td class='panel-daynames'>".substr($locale['day_sun'], 0, 1)."</td>\n";
  95. echo "</tr>\n";
  96.  
  97. // START TIME - END TIME for all the Events in a Month
  98. $monthstart = mktime(0, 0, 0, $month, 1, $year);    // Make Date of 1'st Day
  99. $monthend = mktime(24, 0, 0, $month, date("t", $monthstart), $year);    // Make Date of Last Day
  100.  
  101. // Retrieve all the Events in the Current Month
  102. $monthevents = dbquery("SELECT event_id, event_title, event_startdate FROM ".DB_EVENTS." WHERE ".groupaccess('event_visibility')." AND (event_startdate>=".$monthstart." AND event_startdate<=".$monthend.") AND event_hidden='0' ORDER BY event_startdate");
  103.  
  104. // Array to Store all Events
  105. $allevents = array();
  106.  
  107. while ($data = dbarray($monthevents))
  108. {
  109.     $event_date = date("j", $data['event_startdate']);
  110.     $allevents[$event_date][$data['event_id']] = $data['event_title'];
  111. }
  112.  
  113. // Birthdays
  114. // Store Birthdays in a Variable
  115. $birthdays_cache = array();
  116.  
  117. if ($emssettings['ems_show_birthdays_calendar'] == 1)
  118. {
  119.     // Find all birthdays in Current Month
  120.     $birthdays = dbquery("SELECT user_name, user_id, user_birthdate FROM ".DB_USERS." WHERE user_birthdate LIKE '%-".date("m", $monthstart)."-%'");
  121.  
  122.     if (dbrows($birthdays) > 0)
  123.     {
  124.         while ($data = dbarray($birthdays))
  125.         {
  126.             $dob = explode("-", $data['user_birthdate']);
  127.             $age = $year-$dob[0];
  128.             $birthdays_cache[trim($dob[2], "0")][$data['user_id']] = $data['user_name']."(".$age.")";    // Trim is used to Remove Leading Zero
  129.         }
  130.     }
  131. }
  132.  
  133. // Printing Dates on Calendar
  134. for ($i=0; $i<($days_in_month+$day_of_week); $i++)
  135. {
  136.     // Actual Day Number
  137.     $count = ($i - $day_of_week + 1);
  138.  
  139.     // First Day of the Week
  140.     // Every week will be shown by 1 TR
  141.     if(($i % 7) == 0)
  142.     {
  143.         echo "<tr>\n";
  144.     }
  145.  
  146.     // If $i is less than Starting Day of Week, then Print Empty TDs
  147.     if($i < $day_of_week)
  148.     {
  149.         // Exception: If Week doesn't starts from Sunday, then we should print Empty TDs
  150.         if ($day_of_week != 7)
  151.         {
  152.             echo "\t<td class='panel-dates panel-date'></td>\n";
  153.         }
  154.     }
  155.     else
  156.     {
  157.         // If Today's Date comes in the Calendar, then Highlight it by applying Style
  158.         $selected = ((($this_month == $month) && ($this_year == $year) && ($this_date == $count)) ? " current-day" : " panel-date");
  159.         $rightborder = (($i%7==6)||($i == ($days_in_month+$day_of_week-1)) ? " panel-rightborder" : "");
  160.         // Find if there is any Event/Birthday on this Date or Not
  161.         $has_events = ((array_key_exists($count, $allevents) || (array_key_exists($count, $birthdays_cache))) ? " has-events" : "");
  162.  
  163.         // If the Day counter has started, then print the Dates
  164.         echo "\t<td valign='middle' class='panel-dates".$selected.$rightborder.$has_events."'><a id='panel_day_".$count."' href='".EMSDIR."calendar.php?month=".$month."&amp;year=".$year."&amp;day=".$count."'>".$count."</a></td>\n";
  165.     }
  166.  
  167.     // If it is the Last Day of Week, then Finish it with </TR>
  168.     if(($i % 7) == 6)
  169.     {
  170.         echo "</tr>\n";
  171.     }
  172.  
  173.     // If it is the Last Date of the month, then Finish it with </TR>
  174.     if($i == ($days_in_month+$day_of_week-1))
  175.     {
  176.         echo "</tr>\n";
  177.     }
  178. }
  179.  
  180. // Javascript Code for Bubble Tip
  181. $js_code_to_add = "";
  182.  
  183. for ($i=1; $i<=date("t", $monthstart); $i++)
  184. {
  185.     if (array_key_exists($i, $allevents) || array_key_exists($i, $birthdays_cache))
  186.     {
  187.         echo "<div class='panel-event-bubble-tip' id='panel_daytip_".$i."' style='display:none;'>\n";
  188.         if (array_key_exists($i, $allevents))    {
  189.             foreach ($allevents[$i] as $key=>$val)
  190.             {
  191.                 echo "<a href='".EMSDIR."events.php?event=".$key."'><img src='".EMSDIR."images/calendar_icon_small.png' alt='' border='0' class='calendar-icon-small' /> ".$val."</a><br />\n";
  192.             }
  193.         }
  194.         if (array_key_exists($i, $birthdays_cache))    {
  195.             foreach ($birthdays_cache[$i] as $key=>$val)
  196.             {
  197.                 echo "<a href='".BASEDIR."profile.php?lookup=".$key."'><img src='".EMSDIR."images/birthday.png' alt='' border='0' class='birthday-icon-small' /> ".$val."</a><br />\n";
  198.             }
  199.         }
  200.         echo "</div>\n";
  201.         $js_code_to_add .= "$('#panel_day_".$i."').bubbletip($('#panel_daytip_".$i."'), { deltaDirection: '".$emssettings['ems_panel_tip_direction']."' });\n";
  202.     }
  203. }
  204.  
  205. // Add Javascript to Header
  206. if ($js_code_to_add != "")
  207. {
  208. add_to_head("<script type='text/javascript'>
  209. $(window).bind('load', function() {
  210. ".$js_code_to_add."});
  211. </script>");
  212. }
  213.  
  214. ?>


The ajax code is from the Ajax Caledar infusion

Thanks for the help!
 
Jump to Forum:

Similar Threads

Thread Forum Replies Last Post
[PANEL] Top 5 Downloads [7.02.XX] Code Snippets 2 05-23-2018 02:09
Donate Panel [7.02.XX] Code Snippets 13 09-11-2017 22:23
users online panel Addon Requests 2 01-02-2017 09:46
[Themes] Blog-e how to add panel [7.02.XX] Themes 5 07-10-2016 02:04
Include Custom Login Panel General Chat 1 05-17-2015 07:39