Jump to content

Search the Community

Showing results for tags 'calendar'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 15 results

  1. I have the week date range displaying the week range from sunday - saturday $current_dayname = date("0"); // return sunday monday tuesday etc. echo $date = date("Y-m-d",strtotime('last sunday')).'to'.date("Y-m-d",strtotime("next saturday")); Which outputs in the following format 2015-01-25to2015-01-31 However, when I press next or previous, the dates don't change. <?php $year = (isset($_GET['year'])) ? $_GET['year'] : date("Y"); $week = (isset($_GET['week'])) ? $_GET['week'] : date('W'); if($week > 52) { $year++; $week = 1; } elseif($week < 1) { $year--; $week = 52; } ?> <a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week == 52 ? 1 : 1 + $week).'&year='.($week == 52 ? 1 + $year : $year); ?>">Next Week</a> <!--Next week--> <a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week == 1 ? 52 : $week -1).'&year='.($week == 1 ? $year - 1 : $year); ?>">Pre Week</a> <!--Previous week--> <table border="1px"> <tr> <td>user</td> <?php if($week < 10) { $week = '0'. $week; } for($day= 1; $day <= 7; $day++) { $d = strtotime($year ."W". $week . $day); echo "<td>". date('l', $d) ."<br>". date('d M', $d) ."</td>"; } ?> </tr> </table>
  2. I found a tutorial on youtube that would allow me to create a calendar of events. We have the calendar html page: This includes the onload="initialCalendar();" function <script type="text/javascript"> /* <![CDATA[ */ function initialCalendar(){ var hr = new XMLHttpRequest(); var url = "calendar/calendar_start.php"; var currentTime = new Date (); var month = currentTime.getMonth() + 1; var year = currentTime.getFullYear(); showmonth = month; showyear = year; var vars= "showmonth="+showmonth+"&showyear="+showyear; hr.open("POST", url, true); hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange = function() { if (hr.readyState == 4 && hr.status == 200) { var return_data = hr.responseText; document.getElementById("showCalendar").innerHTML = return_data; } } hr.send(vars); document.getElementById("showCalendar"). innerHTML = "processing..."; } /* ]]> */ </script> <script type="text/javascript"> /* <![CDATA[ */ function next_month() { var nextmonth = showmonth + 1; if(nextmonth > 12) { nextmonth = 1; showyear = showyear+1; } showmonth = nextmonth; var hr = new XMLHttpRequest(); var url = "calendar/calendar_start.php"; var vars= "showmonth="+showmonth+"&showyear="+showyear; hr.open("POST", url, true); hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange = function() { if (hr.readyState == 4 && hr.status == 200) { var return_data = hr.responseText; document.getElementById("showCalendar").innerHTML = return_data; } } hr.send(vars); document.getElementById("showCalendar"). innerHTML = "processing..."; } /* ]]> */ </script> <script type="text/javascript"> /* <![CDATA[ */ function last_month() { var lastmonth = showmonth - 1; if(lastmonth < 1 ) { lastmonth = 12; showyear = showyear-1; } showmonth = lastmonth; var hr = new XMLHttpRequest(); var url = "calendar/calendar_start.php"; var vars= "showmonth="+showmonth+"&showyear="+showyear; hr.open("POST", url, true); hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange = function() { if (hr.readyState == 4 && hr.status == 200) { var return_data = hr.responseText; document.getElementById("showCalendar").innerHTML = return_data; } } hr.send(vars); document.getElementById("showCalendar"). innerHTML = "processing..."; } /* ]]> */ </script> <script type="text/javascript"> /* <![CDATA[ */ function overlay() { el = document.getElementById("overlay"); el.style.display = (el.style.display == "block") ? "none" : "block"; el = document.getElementById("events"); el.style.display = (el.style.display == "block") ? "none" : "block"; el = document.getElementById("eventsBody"); el.style.display = (el.style.display == "block") ? "none" : "block"; } /* ]]> */ </script> <script type="text/javascript"> /* <![CDATA[ */ function show_details(theId) { var deets = (theId.id); el = document.getElementById("overlay"); el.style.display = (el.style.display == "block") ? "none" : "block"; el = document.getElementById("events"); el.style.display = (el.style.display == "block") ? "none" : "block"; var hr = new XMLHttpRequest(); var url = "calendar/events_fns.php"; var vars = "deets="+deets; hr.open("POST", url, true); hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange= function() { if (hr.readyState == 4 && hr.status == 200) { var return_data = hr.responseText; document.getElementById("events").innerHTML = return_data; } } hr.send(vars); document.get ElementById("events").innerHTML = "processing..."; } /* ]]> */ </script> The script to show to actual calendar is called from here.... calendar_start.php <?php $showmonth = $_POST['showmonth']; $showyear = $_POST['showyear']; $showmonth= preg_replace('#[^0-9]#i', '', $showmonth); $showyear= preg_replace('#[^0-9]#i', '', $showyear); $day_count = cal_days_in_month(CAL_GREGORIAN, $showmonth, $showyear); $pre_days = date('w', mktime(0,0,0, $showmonth, 1, $showyear)); $post_days = (6-(date('w', mktime(0,0,0, $showmonth, $day_count, $showyear)))); echo '<div id="calendar-wrap">'; echo '<div class="title-bar">'; echo '<div class="previous-month"><input name="button" type="submit" value="Previous Month" onClick="javascript:last_month();"></div>'; echo '<div class="show-month">' . date('F', mktime(0, 0, 0, $showmonth)) . ' ' . $showyear . '</div>'; echo '<div class="next-month"><input name="button" type="submit" value="Next Month" onClick="javascript:next_month();"></div>'; echo '</div>'; echo '<div class="week_days">'; echo '<div class="days-of-week">Sun</div>'; echo '<div class="days-of-week">Mon</div>'; echo '<div class="days-of-week">Tues</div>'; echo '<div class="days-of-week">Wed</div>'; echo '<div class="days-of-week">Thur</div>'; echo '<div class="days-of-week">Fri</div>'; echo '<div class="days-of-week">Sat</div>'; echo '<div class="clear"></div>'; echo '</div>'; //Previous Month days if ($pre_days != 0) { for($i=1; $i<=$pre_days; $i++) { echo '<div class="non-cal-days"></div>'; } } //Current Month Days $conn = mysqli_connect('Databaseconnection Things') or die ("Could not connect to the Database"); for ($i=1; $i<= $day_count; $i++) { //get event logic $date = $i.'/'.$showmonth.'/'.$showyear; $query = mysqli_query('SELECT calid FROM calendar WHERE caldate = "'.$date.'"') or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($query), E_USER_ERROR); $num_rows = mysqli_num_rows($conn, $query); if($num_rows > 0) { $event = "<input name='$date' type='submit' value='Details' id='$date' onClick='javascript:show_details(this);'>"; } echo '<div class="cal-days">'; echo '<div class="day-heading">' . $i . '</div>'; if($num_rows != 0) { echo "<div class='opening'><br/>" . $event . "</div>";} echo '</div>'; } //Next Months Days if ($post_days !=0) { for($i=1; $i<=$post_days; $i++) { echo '<div class="non-cal-days"></div>'; } } echo '</div>'; ?> And events_fns. <?php $deets = $_POST['deets']; $deets = preg_replace('#[^0-9/]#i', '', $deets); $conn = mysqli_connect("Database Connection") or die ("Could not connect to the Database"); $events = ''; $query = mysqli_query('SELECT calid FROM calendar WHERE caldate = "'.$deets.'"') or die ("Error:".mysqli_errno()); //echo "$query"; $num_rows=0; if ($result = mysqli_query($query,$conn)) { $num_rows = mysqli_num_rows($result); } if ($num_rows > 0) { $events .= '<div id="eventsControl"><button onMouseDown="overlay()">Close</button><br /><br />'.$deets.'<br /><br /></div>'; while ($row = mysqli_fetch_array($query)) { $title = $row['eventtitle']; $desc = $row['description']; $loc = $row['eventlocation']; $events .='<div id="eventsBody">'.$title.'<br />'.$desc.'<br />'.$loc.'<hr /></div>'; } } echo $events; ?> I have posted all the code so you can see how it fits together ect ect however the issue I am having is an error message that repeats across the page. it reads: Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in /home/sites/agile-cms.co.uk/public_html/mfcf/calendar/calendar_start.php on line 49 Fatal error: Query Failed! SQL: - Error: in /home/sites/agile-cms.co.uk/public_html/mfcf/calendar/calendar_start.php on line 49 for ($i=1; $i<= $day_count; $i++) { //get event logic $date = $i.'/'.$showmonth.'/'.$showyear; $query = mysqli_query($conn, 'SELECT eventid FROM events WHERE eventdate = "'.$date.'"') or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($query), E_USER_ERROR); $num_rows = mysqli_num_rows($query); if($num_rows > 0) { $event = "<input name='$date' type='submit' value='Details' id='$date' onClick='javascript:show_details(this);'>"; } echo '<div class="cal-days">'; echo '<div class="day-heading">' . $i . '</div>'; if($num_rows != 0) { echo "<div class='opening'><br/>" . $event . "</div>";} echo '</div>'; } I think I have missed something being so close to it and I think I need an outside P.O.V to look at it and point me in the right direction.... Any help would be much appreciated....
  3. I registered a few days ago for help on this thread but didn't post again on it now because it has been marked answered and I thought I'd better not bump it. I received help in a way that has been the most encouraging since I began my calendar project. I'm wondering, though, if you would help me understand why I'm not successful at implementing the advice to the point that events are inserting into my calendar. My testing database has only one table: events and in events, only two columns (other than id): "startdt" and "description". This is a screenshot of how the table's columns are set upL This is a screenshot of the table content: This is my code with the edits added from the support thread: <?PHP $var = mysql_real_escape_string($_GET['startdt, description']); $con=mysql_connect("localhost","user","password"); // Check connection if (mysql_connect_error()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } //select a database to work with $selected = mysql_select_db("mydatabase_",$con) or die("Could not select mydatabase_"); //execute the SQL query and return records $result = mysql_query("SELECT information FROM events WHERE value='$startdt', 'description'"); //fetch tha data from the database while ($row = mysql_fetch_array($result)) { echo $row{'startdt, description'}; } //close the connection mysql_close($con); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="css/master.css" type="text/css" media="all"> <meta http-equiv="Content-Type" content="text/html" /> <title>Yet Another Test</title> </head> <body> <?php $currMonth = isset($_GET['month']) ? $_GET['month'] : date('n'); $currYear = isset($_GET['year']) ? $_GET['year'] : date('Y'); $today = (($currYear == date('Y')) && ($currMonth == date('n'))) ? date('j') : 0; $prevMonth = $currMonth==1 ? 12 : $currMonth-1; $nextMonth = $currMonth==12? 1 : $currMonth+1; $prevYear = $currMonth==1 ? $currYear-1 : $currYear; $nextYear = $currMonth==12? $currYear+1 : $currYear; $day1 = mktime(0,0,0,$currMonth,1,$currYear); $dim = date('t', $day1); $dayN = mktime(0,0,0,$currMonth,$dim,$currYear); $dow1 = (date('w',$day1)+0) % 7; $dowN = (date('w',$dayN)+0) % 7; $calHead = date('F Y',$day1); echo <<<EOT <div class="calwrapper"> <div class="caltitle"><h1>Calendar</h1></div> <div class="container"> <div class="fnl first"></div> <div class="adjust"></div> <div class="fnl last"></div> </div> <div class="caldisplay"> <table cellspacing="0"> <tr> <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$prevYear&month=$prevMonth"> Prev </a></td> <td colspan="5" class="adjust">$calHead</td> <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$nextYear&month=$nextMonth"> Next </a></td> </tr> <tr> <th class="we">Sun</th> <th class="wd">Mon</th> <th class="wd">Tue</th> <th class="wd">Wed</th> <th class="wd">Thu</th> <th class="wd">Fri</th> <th class="we">Sat</th> </tr> <tr> EOT; for ($d=0;$d<$dow1;$d++) echo "<td class=\"hd\"> </td>"; $c = $dow1; for ($d=1; $d<=$dim; $d++, $c++) { if ($c%7==0) echo "</tr><tr>"; $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd'; $st = ($d == $today) ? "style='padding: 0px;'" : ''; echo "<td class=\"$cl\" $st>\n"; echo "$d" ; echo "</td>\n"; } while ($c++ % 7 != 0) echo '<td class=\"hd\"> </td>'; echo "</tr></table>\n"; echo '</div></div>'; // calander entries. Use the date as the key (in YYYY/MM/DD format) $entries = array( '2014/8/16' => array( 'Event', ), ); for ($d=1; $d<=$dim; $d++, $c++) { if ($c%7==0) echo "</tr><tr>"; $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd'; $st = ($d == $today) ? "style='padding: 0px;'" : ''; echo "<td class=\"$cl\" $st>\n"; echo "$d" ; echo "</td>\n"; } // construct the date, this will be used to check to if the key exists in the $entries array $dateKey = "$currYear/$currMonth/$d"; // check if the key exists in the $entries array if(array_key_exists($dateKey, $entries)) { // for each event, list it in a seperate tool tip foreach($entries[$dateKey] as $entry) { echo '<div class="has-tooltip"> Event <span class="tooltip">'.$entry.'</span> </div>'; } } ?> </body> </html> I am not getting any errors in the PHP Code Checker (although I am receiving the notice that these functions are now deprecated): mysql_close() mysql_connect() mysql_fetch_array() mysql_query() mysql_real_escape_string() mysql_select_db() When I upload my page to the server, everything seems fine, except that no information is added to the table. When I check the page source, I see this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="css/master.css" type="text/css" media="all"> <meta http-equiv="Content-Type" content="text/html" /> <title>Yet Another Test</title> </head> <body> <div class="calwrapper"> <div class="caltitle"><h1>Calendar</h1></div> <div class="container"> <div class="fnl first"></div> <div class="adjust"></div> <div class="fnl last"></div> </div> <div class="caldisplay"> <table cellspacing="0"> <tr> <td class="hd"><a class="cal_button" href="/1cal/calendar.php?year=2014&month=7"> Prev </a></td> <td colspan="5" class="adjust">August 2014</td> <td class="hd"><a class="cal_button" href="/1cal/calendar.php?year=2014&month=9"> Next </a></td> </tr> <tr> <th class="we">Sun</th> <th class="wd">Mon</th> <th class="wd">Tue</th> <th class="wd">Wed</th> <th class="wd">Thu</th> <th class="wd">Fri</th> <th class="we">Sat</th> </tr> <tr><!--DEBUG: year=$currYear and month=$currMonth<hr/--><td class="hd"> </td><td class="hd"> </td><td class="hd"> </td><td class="hd"> </td><td class="hd"> </td><td class="we" > 1</td> <td class="we" > 2</td> </tr><tr><td class="wd" > 3</td> <td class="wd" > 4</td> <td class="wd" > 5</td> <td class="wd" > 6</td> <td class="wd" > 7</td> <td class="we" > 8</td> <td class="we" > 9</td> </tr><tr><td class="wd" > 10</td> <td class="wd" > 11</td> <td class="wd" > 12</td> <td class="wd" > 13</td> <td class="wd" > 14</td> <td class="we" style='padding: 0px;'> 15</td> <td class="we" > 16</td> </tr><tr><td class="wd" > 17</td> <td class="wd" > 18</td> <td class="wd" > 19</td> <td class="wd" > 20</td> <td class="wd" > 21</td> <td class="we" > 22</td> <td class="we" > 23</td> </tr><tr><td class="wd" > 24</td> <td class="wd" > 25</td> <td class="wd" > 26</td> <td class="wd" > 27</td> <td class="wd" > 28</td> <td class="we" > 29</td> <td class="we" > 30</td> </tr><tr><td class="wd" > 31</td> <td class=\"hd\"> </td><td class=\"hd\"> </td><td class=\"hd\"> </td><td class=\"hd\"> </td><td class=\"hd\"> </td><td class=\"hd\"> </td></tr></table> </div></div></body> </html> I don't have an understanding of what the Debug is telling me although I note the number "1" within the tag and find that interesting because on those occasions, earlier today, when the file upload would result in a white page, viewing the page source would reveal nothing but the numeral "1" in the upper left top. Are the deprecated functions enough to cause the event not to insert into the calendar? I'd appreciate any help in sorting why I'm not succeeding. As you see so often around here, I'm not a coder. I'm just forced into a position to have to fend for myself, as of late, and so I'm trying to learn what I can. Thank you for any help.
  4. Hi. I'm trying to achieve a calendar that only uses PHP and CSS. I registered today to ask for help (because I'm not a coder; I'm just another clueless musician). My goal is to just skip the database, altogether. I've already, so far, skipped the Javascript, as well. I have an HTML non-functioning mockup HERE that's a bit "off" cosmetically, but I'm just using it as an example. It has a made-up "event" on August 16. I'm just using a little "tooltip" CSS. (I have no idea how it works in IE, it's just me and my MacBook here, but still... you get the idea of the function.) Or I might use THIS to get it to work for IOS, but that needs a little aesthetic work. Not tinkering with all that today. Now... my PHP created calendar, that I will actually be using, is HERE. All the structure of the calendar is echoed in PHP so there is no actual HTML hard coding of table cells. In fact, the only HTML within the body is <body></body> So, I can't very well just pick a date and type in some tags and be off. My question is this (and because I don't really know correct PHP jargon to formulate a question, I'm not being successful at Googling): Is it possible to use PHP to isolate a specific date, say, in this case, August 16 2014, and then, based upon that date existing, echo what I have hard-coded into the mockup example: <div class="has-tooltip"> Event <span class="tooltip">Concert In The Park<br /> 123 City Park Drive<br /> AnyTown, STATE 00000<br /> <a href="http://example.com" target="_blank">More Info</a><br /> or call 555.123.4567<br /></span> </div> I realize that this means that there's always a great chance of error, but this wouldn't be a calendar with any other users inserting dates; it's nothing more than an occasional event and then it's over, and I would be the one posting the events, so I'd be able to test it before publishing it. Possible? And if so, would you advise as how to get PHP to isolate a particular date and then echo the HTML and, of course, have it reside in the date-appropriate table cell? (I've managed to echo HTML to build the calendar structure, but I've never created an echo in conjunction with calling for a specific date. I'd appreciate any help and thanks so much. PHP: <?php $currMonth = isset($_GET['month']) ? $_GET['month'] : date('n'); $currYear = isset($_GET['year']) ? $_GET['year'] : date('Y'); $today = (($currYear == date('Y')) && ($currMonth == date('n'))) ? date('j') : 0; $prevMonth = $currMonth==1 ? 12 : $currMonth-1; $nextMonth = $currMonth==12? 1 : $currMonth+1; $prevYear = $currMonth==1 ? $currYear-1 : $currYear; $nextYear = $currMonth==12? $currYear+1 : $currYear; $day1 = mktime(0,0,0,$currMonth,1,$currYear); $dim = date('t', $day1); $dayN = mktime(0,0,0,$currMonth,$dim,$currYear); $dow1 = (date('w',$day1)+0) % 7; $dowN = (date('w',$dayN)+0) % 7; $calHead = date('F Y',$day1); echo <<<EOT <div class="calwrapper"> <div class="caltitle"><h1>Calendar</h1></div> <div class="container"> <div class="fnl first"></div> <div class="adjust"></div> <div class="fnl last"></div> </div> <div class="caldisplay"> <table cellspacing="0"> <tr> <td class="hd"><a class="cal_button" href="$_SERVER[php_SELF]?year=$prevYear&month=$prevMonth"> Prev </a></td> <td colspan="5" class="adjust">$calHead</td> <td class="hd"><a class="cal_button" href="$_SERVER[php_SELF]?year=$nextYear&month=$nextMonth"> Next </a></td> </tr> <tr> <th class="we">Sun</th> <th class="wd">Mon</th> <th class="wd">Tue</th> <th class="wd">Wed</th> <th class="wd">Thu</th> <th class="wd">Fri</th> <th class="we">Sat</th> </tr> <tr> EOT; for ($d=0;$d<$dow1;$d++) echo "<td class=\"hd\"> </td>"; $c = $dow1; for ($d=1; $d<=$dim; $d++, $c++) { if ($c%7==0) echo "</tr><tr>"; $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd'; $st = ($d == $today) ? "style='padding: 0px;'" : ''; echo "<td class=\"$cl\" $st>\n"; echo "$d" ; echo "</td>\n"; } while ($c++ % 7 != 0) echo '<td class=\"hd\"> </td>'; echo "</tr></table>\n"; echo '</div></div>'; ?>
  5. Hello. A bit of warning up front: I'm an anthropologist, not a programmer, so a great deal of this goes right over my head! I've been working for a couple of years now on reconstructing an Iron Age I Canaanite calendar. The math is done, and thanks to the assistance of Alex over at timemeddler.co.uk, a great deal of the code is done as well. I've hit a bit of a snag, however. While the code I have prints a nice, neat table with Gregorian dates on the left and Canaanite/Israelite dates on the right, there are a couple of extra things I'd like it to do that I just can't figure out. 1. I desperately need the column which currently says "What goes here to make holidays?" to actually have holidays in it. I have no idea how to do this. I'd love for it to be hard coded, as the holidays are fixed and I'd rather not go through SQL databases. They would need to correspond to specific Canaanite/Israelite dates, probably utilizing the $isr_month and $isr_day. I'd love it if the list of holidays was built into orecha.inc so that it was usable elsewhere. I know this is possible, I just have NO idea how to get it to work, primarily due to a lack of experience with PHP. 2. I'd love to have the table print as a calendar format, with each Gregorian month separate and the Israelite/Canaanite dates and holidays contained withing the individual cells, like events. I'm sure that's a bit more complex, so it's not necessary, but strongly wanted. Here's my primary PHP and the relevant INC files: OQ_Calendar.php <?php session_start (); # orecha_test.php - test script for Israelite lunar calendar include "includes/gregorian.inc"; include "includes/orecha.inc"; include "includes/html.inc"; include "includes/common.inc"; $title = "Israelite Calendar Test Script"; html_begin ($title,""); $this_year = date('Y'); $test_year = 2014; // Change this to query different Gregorian years. print "<br><b>$test_year</b>"; $start_date = fixed_from_gregorian($test_year, 1, 1); $end_date = fixed_from_gregorian($test_year, 12, 31); print "<table width=710 border=0>"; for ($test_date = $start_date; $test_date <= $end_date; $test_date++) { print "<tr>"; $gregorian_from_fixed = gregorian_from_fixed($test_date); $greg_day = $gregorian_from_fixed[0]; $greg_month = $gregorian_from_fixed[1]; $greg_year = $gregorian_from_fixed[2]; $israelite_count = israelite_from_fixed($test_date); $isr_cycle = $israelite_count[0]; $isr_year = $israelite_count[1]; $isr_month = $israelite_count[2]; $isr_day = $israelite_count[3]; $israelite_year = israelite_year_from_count($isr_cycle, $isr_year); print "<td width=140 align=right>$greg_day $months[$greg_month] $greg_year</td>"; print "<td width=60 align=center> = </td>"; print "<td width=200 align=left> $isr_day <i>$israelite_months[$isr_month]</i>, $israelite_year</td>"; print "<td width=200 align=left>What goes here to make holidays?</td>"; print "</tr>"; } print "</table>"; print "<br>-------------------------------------------------------"; html_end (); #---------------------------------------------------------------------- gregorian.inc <?php $months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', 'Leap Week'); $short_months = array (1 => 'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); function gregorian_leap_year($g_year) { $gregorian_leap_year = FALSE; if (($g_year % 4 == 0) && ($g_year % 400 != 100 && $g_year % 400 != 200 && $g_year % 400 != 300)) { $gregorian_leap_year = TRUE; } return $gregorian_leap_year; } function fixed_from_gregorian($g_year, $g_month, $g_day) { $fixed_date = 365 * ($g_year - 1); $fixed_date += FLOOR(($g_year - 1) / 4) - FLOOR(($g_year - 1) / 100) + FLOOR(($g_year - 1) / 400); $fixed_date += FLOOR((367 * $g_month - 362) / 12); if ($g_month > 2) { if (gregorian_leap_year($g_year)) { $fixed_date -= 1; } else { $fixed_date -= 2; } } $fixed_date += $g_day; return $fixed_date; } function gregorian_new_year($g_year) { $gregorian_new_year = fixed_from_gregorian($g_year, 1, 1); return $gregorian_new_year; } function gregorian_year_end($g_year) { $gregorian_year_end = fixed_from_gregorian($g_year, 12, 31); return $gregorian_year_end; } function gregorian_year_from_fixed($fixed_date) { $d0 = $fixed_date - 1; $n400 = FLOOR($d0 / 146097); $d1 = $d0 % 146097; $n100 = FLOOR($d1 / 36524); $d2 = $d1 % 36524; $n4 = FLOOR($d2 / 1461); $d3 = $d2 % 1461; $n1 = FLOOR($d3 / 365); if (($n100 == 4) || ($n1 == 4)) { $gregorian_year_from_fixed = 400 * $n400 + 100 * $n100 + 4 * $n4 + $n1; } else { $gregorian_year_from_fixed = 400 * $n400 + 100 * $n100 + 4 * $n4 + $n1 + 1; } return $gregorian_year_from_fixed; } function gregorian_from_fixed($fixed_date) { $months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); $g_year = gregorian_year_from_fixed($fixed_date); $prior_days = $fixed_date - gregorian_new_year($g_year); $march1 = fixed_from_gregorian($g_year, 3, 1); $leap_year = gregorian_leap_year($g_year); if ($fixed_date < $march1) { $correction = 0; } else if ($leap_year) { $correction = 1; } else { $correction = 2; } $g_month = FLOOR((12 * ($prior_days + $correction) + 373) / 367); $day1 = fixed_from_gregorian($g_year, $g_month, 1); $g_day = 1 + $fixed_date - $day1; $gregorian_from_fixed = array ($g_day, $g_month, $g_year); return $gregorian_from_fixed; } ?> orecha.inc <?php $days_in_era = 121991; $days_in_cycle = array ( 1=> 6940, 6940, 6939); $days_in_year = array ( 1=> 384, 354, 354, 384, 354, 355, 384, 354, 355, 384, 354, 384, 354, 355, 384, 354, 355, 384, 354); $days_in_month = array ( 1=> 30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 30); $israelite_months = array ( 1=> 'Yeraḥ ʼĀḇīḇ', 'Yeraḥ Zīw', 'Yeraḥ ʼĂp̄īlaṯ', 'Yeraḥ Marəpēʼ', 'Yeraḥ Ṣaḥ', 'Yeraḥ Pəḡārīm', 'Yeraḥ ʼĒṯānīm', 'Yeraḥ Būl', 'Yeraḥ Qōreṯ', 'Yeraḥ Zeḇaḥ Šemeš', 'Yeraḥ Ḥūrī', 'Yeraḥ Gīḇəʻōl', 'Yeraḥ Mēp̄āʻaṯ'); $israelite_epoch = fixed_from_gregorian(-1475, 3, 30); function israelite_day_number($date) { global $israelite_epoch; $israelite_day_number = $date - $israelite_epoch + 1; return $israelite_day_number; } function israelite_from_fixed($date) { global $prior_days, $days_in_era, $days_in_cycle, $days_in_year, $days_in_month; // Calculate eras elapsed and days elapsed in current era // An era is one "grand cycle" of 17 19-year cycles and one 11-year cycle, // a total of 121,991 days, or 1 less in every 6th and 13th era $era_count = 0; $days_remaining = israelite_day_number($date); while ($days_remaining > 0) { $era_count++; if ($era_count % 6 == 0) { $days_in_era = 121990; } elseif ($era_count % 13 == 0) { $days_in_era = 121990; } else { $days_in_era = 121991; } $days_elapsed_in_era = $days_remaining; $days_remaining -= $days_in_era; } $days_remaining = $days_elapsed_in_era; $era_count--; // Calculate cycles elapsed and days elapsed in current cycle $cycle_count = $era_count * 18 + 1; while ($days_remaining > 0) { $days_elapsed_in_cycle = $days_remaining; $cycle_index = $cycle_count % 3; if ($cycle_index == 0) {$cycle_index = 3;} $days_remaining -= $days_in_cycle[$cycle_index]; $cycle_count++; } $days_remaining = $days_elapsed_in_cycle; $cycle_count--; // Calculate years elapsed in current cycle and days elapsed in current year $year_count = 1; if ($cycle_count % 3 == 3) { $days_in_year[19] = 354; } while ($days_remaining > 0) { $days_elapsed_in_year = $days_remaining; $days_remaining -= $days_in_year[$year_count]; $year_count++; } $days_remaining = $days_elapsed_in_year; $year_count -= 1; // Calculate months elapsed in current year and days elapsed in current month $month_count = 1; if ($cycle_count % 3 == 3) { if (($year_count == 6) || ($year_count == 9) || ($year_count == 14)) { $days_in_month[6] = 30; } else { $days_in_month[6] = 29; } } elseif ($cycle_count % 18 == 0) { if (($year_count == 6) || ($year_count == 9)) { $days_in_month[6] = 30; } else { $days_in_month[6] = 29; } } else { if (($year_count == 6) || ($year_count == 9) || ($year_count == 14) || ($year_count == 17)) { $days_in_month[6] = 30; } else { $days_in_month[6] = 29; } } while ($days_remaining > 0) { $days_elapsed_in_month = $days_remaining; $days_remaining -= $days_in_month[$month_count]; $month_count++; } $days_remaining = $days_elapsed_in_month; $month_count -= 1; $day_count = $days_elapsed_in_month; $israelite_count = array ($cycle_count, $year_count, $month_count, $day_count); return $israelite_count; } function israelite_year_from_count($cycle_count, $year_count) { $israelite_era = ceil($cycle_count / 18); $cycles = $cycle_count - ($israelite_era - 1) * 18; $israelite_year = (($israelite_era - 1) * 334) + ($cycles - 1) * 19 + $year_count; return $israelite_year; } ?> html.inc <?php function html_begin ($title, $header) { print ("<html>\n"); print ("<head>\n"); if ($title != "") print ("<title>$title</title>\n"); print ("<LINK REL=stylesheet TYPE='text/css' HREF='mystyle.css'>"); print ("</head>\n"); # print ("<BODY bgcolor='#2D6840'>"); print ("<BODY bgcolor='#CCCCFF'>"); print ("<div id='main' class='main'>"); print ("<table width='600' cellpadding='5'>"); } function html_end () { // print ("<p><i>� Time Meddler $x_year</i></p>"); print ("</div>"); print ("</body></html>"); } ?> common.inc <?php $months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', 'Leap Week'); $sunday = 0; # Index constants for locale $latitude = 0; $longitude = 1; $elevation = 2; $zone = 3; $jd_epoch = -1721424.5; function signum($x) { if ($x < 0) { $y = -1; } else if ($x == 0) { $y = 0; } else { $y = 1; } return $y; } function amod($x, $y) { if ($x % $y == 0) { $result = $y; } else { $result = $x % $y; } return $result; } function moment_from_jd($jd) { global $jd_epoch; $moment_from_jd = $jd + $jd_epoch; return $moment_from_jd; } function fixed_from_jd($jd) { $fixed_from_jd = floor(moment_from_jd($jd)); return $fixed_from_jd; } function nth_kday($n, $k, $g_date) { if ($n > 0) { $nth_kday = 7 * $n + kday_before($k, $g_date); } else { $nth_kday = 7 * $n + kday_after($k, $g_date); } return $nth_kday; } function kday_before($k, $date) { $kday_before = kday_on_or_before($k, $date - 1); return $kday_before; } function kday_after($k, $date) { $kday_after = kday_on_or_before($k, $date + 7); return $kday_after; } function kday_on_or_before($k, $date) { $kday_on_or_before = $date - day_of_week_from_fixed($date - $k); return $kday_on_or_before; } function day_of_week_from_fixed($date) { $day_of_week = ($date - 0) % 7; return $day_of_week; } ?> Thank you for any assistance you can provide a poor coding-inept anthropologist!
  6. Hello fellas I have been working on this piece of php for over a week now and I have got a few questions. 1. Where is the $selected_date is being read from ? given that this is a unixtime stamp format , should it not get converted with date function ? The code however is working fine with Gregorian calendar but with persian calendar time conversion , the $selected_date returns as year 1970 instead of 2014. 2. by clicking <a href='calendar.php?month=" . $this->month . "&year=" . $this->year . "&day=" . sprintf("%02s", $daynumber) . "'> what function is being called ? ** the make_time and mds_date are actually from a separated php class which is responsible for the date year and day conversion <?php include 'PersianCalendar.php'; //require_once("PersianCalendar.php"); date_default_timezone_set("Asia/Tehran"); class booking_diary { // Mysqli connection function __construct($link) { $this->link = $link; } /* Settings you can change: $booking_start_time: The time of the first slot $booking_end_time: The time of the last slot $booking_frequency: The amount of slots per hour, expressed in minutes $booking_slots_per_day: The total number of slots avaliable in one day */ public $current_day; public $booking_start_time = "09:00"; public $booking_end_time = "19:00"; public $booking_frequency = 120; public $booking_slots_per_day = 10; public $day, $month, $year, $selected_date, $first_day, $back, $back_month, $back_year, $forward, $forward_month, $forward_year, $bookings, $count, $days; /*========================================================================================================================================================*/ function make_calendar($selected_date, $first_day, $back, $forward, $day, $month, $year) { //persian starts here $year = mds_date("Y"); $chand = mds_date("m"); $fdchand = mds_date("D", make_time(0,0,0,$chand,01,$year)); //going back persian starts $curmonth = mds_date("m", time()); $month = mds_date("m"); $curyear = mds_date("Y", time()); if($curmonth=='01') { $monthnominat = 12; $yearnominat = $curyear-1; } else { $monthnominat = $curmonth-1; $yearnominat = $curyear; } echo date("d m Y" ,$selected_date); $this->current_day = $day; $faselected = mds_date("d, m, Y", $selected_date); var_dump($faselected); $back = make_time(1, 1, 1, $monthnominat, 1, $yearnominat); ////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (empty($selected_date)) { $parts = explode(",", $faselected); $this->month = $parts[1]; $this->day = $parts[0]; $this->year = $parts[2]; $first_day = $this->chandom(mds_date("D", make_time(0, 0, 0, $this->month, 1, $this->year))); $check = 2; } else { $this->day = 0; $this->month = mds_date("m"); $this->year = mds_date("Y"); $first_day = $this->chandom($fdchand); $check = 1; } // Add a value to these public variables echo "<br />"; echo $check; $this->back = $back; $this->back_month = mds_date("m", $back); $this->back_year = mds_date("Y", $back); // Minus one month back arrow $this->selected_date = make_time(24, 0, 0, $this->month, $this->day, $this->year); $this->first_day = $first_day; $this->forward = $forward; $this->forward_month = date("m", $forward); $this->forward_year = date("Y", $forward); // Add one month forward arrow // Make the booking array $this->make_booking_array($year, $month); echo mds_date("F Y", $this->selected_date); } function make_booking_array($year, $month) { $query = "SELECT * FROM bookings WHERE date LIKE '$year-$month%'"; $result = mysqli_query($this->link, $query) or die(mysqli_error($this->link)); $this->count = mysqli_num_rows($result); $this->bookings = ''; while ($row = mysqli_fetch_array($result)) { $this->bookings[] = array( "name" => $row['name'], "date" => $row['date'], "start" => $row['start'], "comments" => $row['comments'] ); } $this->make_days_array( $this->year, $this->month); } // Close function function make_days_array($year, $month) { // Create an array of days in the month //$num_days_month = cal_days_in_month(CAL_GREGORIAN, $month, $year); $num_days_month = dim($month, $year); // Make array called $day with the correct number of days for ($i = 1; $i <= $num_days_month; $i++) { $d = make_time(0, 0, 0, $month, $i, $year); $this->days[] = array("daynumber" => $i, "dayname" => mds_date("l", $d)); } // Add blank elements to start of array if the first day of the month is not a Monday. for ($j = 1; $j <= $this->first_day; $j++) { array_unshift($this->days, '0'); } // Add blank elements to end of array if required. $pad_end = 7 - (count($this->days) % 7); if ($pad_end < 7) { for ($j = 1; $j <= $pad_end; $j++) { array_push($this-> days, '|'); } } // Close if $this->make_table_top(); } // Close function function make_table_top() { echo " <div class='left'> <table border='0' cellpadding='0' cellspacing='0' id='calendar'> <tr id='week'> <td align='left'><a href='?month=" . mds_date("m", $this->back) . "&year=" . mds_date("Y", $this->back) . "'>«</a></td> <td colspan='5' id='center_date'>" . mds_date("F Y", $this->selected_date) . "</td> <td align='right'><a href='?month=" . mds_date("m", $this->forward) . "&year=" . mds_date("Y", $this->forward) . "'>»</a></td> </tr> <tr> <th>شنبه</th><th>یکشنبه</th><th>دوشنبه</th><th>سه شنبه</th><th>چهارشنبه</th><th>پنجشنبه</th><th>جمعه</th>"; $this->make_day_boxes($this->days, $this->bookings, $this->month, $this->year); } // Close function function make_day_boxes() { $i=0; foreach ($this->days as $row) { $tag = ''; if($i % 7 == 0) echo "</tr><tr>"; // Use modulus to give us a <tr> after every seven <td> cells if(isset($row['daynumber']) && $row['daynumber'] != 0) { // Padded days at the start of the month will have a 0 at the beginning echo "<td width='21' valign='top' class='days'>"; if ($this->count > 0) { $day_count = 0; foreach ($this->bookings as $booking_date) { if ($booking_date['date'] == $this->year . '-' . $this->month . '-' . sprintf("%02s", $row['daynumber'])) { $day_count++; } // Close if } // Close foreach } // Close if $count // Work out which colour day box to show if ($row['dayname'] == 'جمعه') $tag = 2; // It's a friday if (make_time(0, 0, 0, $this->month, sprintf("%02s", $row['daynumber']) + 1, $this->year) < strtotime("now")) $tag = 4; // Past Day if ($day_count >= $this->booking_slots_per_day && $tag == '') $tag = 3; if ($day_count >0 && $tag == '') $tag = 1; echo $this->day_switch($tag, $row['daynumber']) . "<span>" . str_replace('|', ' ', $row['daynumber']) . "</span></td>"; } else { echo "<td width='21' valign='top' class='days'><img src='images/block_null.gif' title='مجاز به انتخاب نیستید' alt=''></td>"; } $i++; } // Close foreach $this->make_key(); } // Close function function day_switch($tag, $daynumber) { switch ($tag) { case (1): // Part booked day $txt = "<a href='calendar.php?month=" . $this->month . "&year=" . $this->year . "&day=" . sprintf("%02s", $daynumber) . "'> <img src='images/block_part.gif' title='ساعاتی رزرو شده' border='0' alt=''></a>\r\n"; break; case (2): // friday $txt = "<img src='images/block_sunday.gif' title='روز تعطیل است' border='0' alt=''>\r\n"; break; case (3): // Fully booked day $txt= "<img src='images/block_fully_booked.gif' title='کامل رزرو شده' border='0' alt=''>\r\n"; break; case (4): // Past day $txt = "<img src='images/block_past.gif' title='از تاریخ امروز گذشته' border='0' alt=''></a>\r\n"; break; case (5): // Block booked out day $txt= "<img src='images/block_fully_booked.gif' title='این روز موجود نیست' border='0' alt=''>\r\n"; break; default: // FREE $txt = "<a href='calendar.php?month=" . $this->month . "&year=" . $this->year . "&day=" . sprintf("%02s", $daynumber) . "'> <img src='images/block_free.gif' title='آزاد برای رزرو' border='0' alt=''></a>\r\n"; break; } return $txt; } // Close function function make_key() { // This key is displayed below the calendar to show what the colours represent echo "</tr></table> <table border='0' id='key' cellpadding='2' cellspacing='6'> <tr> <td id='key_1'> </td> <td id='key_2'> </td> <td id='key_3'> </td> <td id='key_4'> </td> <td id='key_5'> </td> </tr> <tr> <td>نبود وقت</td> <td>روز تعطیل</td> <td>حداقل یک وقت رزرو موجود است</td> <td>آزاد</td> <td>گذشته</td> </tr> </table></div>"; $this->make_booking_slots(); } // Close function function make_booking_slots() { /* Variable $day has a default value of 0. If a day has been clicked on, display it. If there is no date selected, show a msg. Otherwise show the booking form. */ if($this->day == 0) { $this->select_day(); } else { $this->make_form(); } } // Close function function select_day() { echo "<form method='post' action=''><div id='selected_date'>لطفا روز رزرواسیون را انتخاب کنید</div>"; } function make_form() { // Create array of the booking times for($i = strtotime($this->booking_start_time); $i<= strtotime($this->booking_end_time); $i = $i + $this->booking_frequency * 60) { $slots[] = date("H:i:s", $i); } echo "\r\n\r\n<form method='post' action=''><div id='selected_date'>تاریخ انتخاب شده: " . $this->month.",". $this->current_day.",". $this->year . "</div>"; $opt = "<select id='select' name='booking_time'><option value='selectvalue'>لطفا زمان رزرواسیون را انتخاب کنید</option>"; if($this->count >= 1) { foreach($this->bookings as $row) { // Check for bookings and remove any previously booked slots foreach($slots as $i => $r) { if($row['start'] == $r && $row['date'] == $this->year . '-' . $this->month . '-' . $this->day) { unset($slots[$i]); } } // Close foreach } // Close foreach } // If count bookings // Make select box from $slots array foreach($slots as $booking_time) { $finish_time = strtotime($booking_time)+ $this->booking_frequency * 60; // Calculate finish time $opt .= "<option value='" . $booking_time . "'>" . $booking_time . " - " . date("H:i:s", $finish_time) . "</option>"; } echo $opt. "</select>"; echo " <table width='300' border='0' id='booking'> <tr> <td class='details'>اسم و فامیلی</td> <td><input class='input' type='text' name='name' size='32'"; if(isset($_POST['name'])) echo " value='" . $_POST['name'] . "'"; echo "></td> </tr> <tr> <td class='details'>ایمیل</td> <td><input class='input' type='text' name='email' size='32'"; if(isset($_POST['email'])) echo " value='" . $_POST['email'] . "'"; echo "></td> </tr> <tr> <td class='details'>تلفن</td> <td><input class='input' type='text' name='phone' size='32'"; if(isset($_POST['phone'])) echo " value='" . $_POST['phone'] . "'"; echo "></td> </tr> <tr> <td class='details'>پیام</td> <td><textarea rows='3' cols='30' name='comments' onclick='make_blank();'>"; if(isset($_POST['comments'])) echo $_POST['comments']; echo "</textarea></td> </tr> <tr> <td> </td> <td> <input type='submit' value='' id='book'></td> </tr> </table></form>"; } function after_post($month, $day, $year) { $alert=''; $msg=0; if(isset($_POST['name']) && empty($_POST['name'])) { $msg = 1; $alert .= "Please fill in the name box<br>"; } if(isset($_POST['email']) && empty($_POST['email'])) { $msg = 1; $alert .= "Please fill in the email box<br>"; } if(isset($_POST['phone']) && empty($_POST['phone'])) { $msg = 1; $alert .= "Please add a contact number<br>"; } if(isset($_POST['booking_time']) && $_POST['booking_time'] == 'selectvalue') { $msg = 1; $alert .= "Please select a booking time"; } if($msg == 1) { echo "<div class='error'>" . $alert . "</div>"; } elseif($msg == 0) { $booking_date = mds_date("Y-m-d", make_time(0, 0, 0, $month, $day, $year)); $booking_time = $_POST['booking_time']; $query = "INSERT INTO bookings (date, start, name, email, phone, comments) VALUES ('$booking_date', '$booking_time', '$_POST[name]', '$_POST', '$_POST[phone]', '$_POST[comments]')"; $result = mysqli_query($this->link, $query) or die(mysqli_error($this->link)); $this->confirm(); } // Close else } // Close function function chandom($fdchand) { if($fdchand=='ج') { $first_day = 6; } if($fdchand=='پ') { $first_day = 5; } if($fdchand=='چ') { $first_day = 4; } if($fdchand=='س') { $first_day = 3; } if($fdchand=='د') { $first_day = 2; } if($fdchand=='ى') { $first_day = 1; } if($fdchand=='ش') { $first_day = 0; } return $first_day; } function confirm() { echo "<div class='success'>وقت شما رزرو شد، لطفا برای اطلاعات بیشتر با دفتر تماس بگیرید</div>"; } // Close function } // Close Class ?>
  7. Hello all, I am working on a event calendar i am taking a basic event calendar and put it into a class so i can make it event's that last for more then just one day each but i got it all working except for i can create 1 event and works fine but if it's more then 1 event it only shows the last one. thank you in advanced. <?php putenv("TZ=America/Chicago"); $time_dif = 0; date_default_timezone_set('America/Chicago'); class Calendar{ private $events = array(); private $start, $end; public function __construct($month = NULL, $year = NULL){ $this->monthNames = array("January","Febuary","March","April","May","June","July","August","September","October","November","December"); $this->weekNames = array("S","M","T","W","T","F","S"); $this->cMonth = $month; $this->cYear = $year; $this->prev_year = $this->cYear; $this->next_year = $this->cYear; $this->prev_month = $this->cMonth-1; $this->next_month = $this->cMonth+1; if($this->prev_month == 0){ $this->prev_month = 12; $this->prev_year = $this->cYear - 1; } if($this->next_month == 13){ $this->next_month = 1; $this->next_year = $this->cYear + 1; } $this->currentmonth = date('n'); $this->currentyear = date('Y'); $this->date = getdate(mktime(0,0,0,$this->cMonth,1,$this->cYear)); $this->timestamp = mktime(0,0,0,$this->cMonth,1,$this->cYear); $this->maxday = date("t", $this->timestamp); $this->thismonth = getdate($this->timestamp); $this->startday = $this->thismonth['wday']; $this->startday2 = date('N', mktime(0,0,0,$this->currentmonth,1,$this->currentyear)) - 0; $this->today = date("j"); } public function addEvent(DateTime $eventStart, DateTime $eventEnd, $description = null){ if($description === NULL){ end($this->events); $description = "Event " . (key($this->events) === null ? 0 : key($this->events) + 1); } $this->events[] = array('start' => $eventStart->format('Y-m-d'), 'end' => $eventEnd->format('Y-m-d'), 'description' => $description); } public function printCalendar(){ $output = '<table width="196" border="1" cellpadding="0" cellspacing="0">'; $output .= ' <tr>'; $output .= ' <td colspan="7">'; $output .= ' <table width="100%" border="0" cellpadding="0" cellspacing="0">'; $output .= ' <tr>'; $output .= ' <td align="center" width="10%">«</td>'; $output .= " <td align='center' width='80%'><strong>{$this->monthNames[$this->cMonth - 1]} {$this->cYear}</strong></td>"; $output .= ' <td align="center" width="10%">»</td>'; $output .= ' </tr>'; $output .= ' </table>'; $output .= ' </td>'; $output .= ' </tr>'; $output .= ' <tr>'; foreach($this->weekNames as $v){ $output .= " <td align='center' width='28' class='txt' background='#999999'><strong>$v</strong></td>"; } $output .= ' </tr>'; for($i=0; $i<($this->maxday+$this->startday); $i++){ if($this->cMonth < 10){ $month_format = "0$this->cMonth"; }else{ $month_format = $this->cMonth; } $cali = ($i - $this->startday + 1); if($cali < 10){ $day_format = "0".$cali.""; }else{ $day_format = $cali; } if(($i % 7) == 0) $output .= "</tr>\n"; $ev = ''; foreach($this->events as $event){ $date = $this->cYear."-".$this->cMonth."-".$cali; if($event['start'] <= $date && $event['end'] >= $date){ $ev = ''; $ev .= "<td align='center' bgcolor='#00FF00' title='".$event['description']."'>$cali</td>"; }elseif($cali == $this->today && $this->currentmonth == $this->cMonth && $this->currentyear == $this->cYear){ $ev = ''; $ev .= "<td align='center' bgcolor='red' title='Today'>$cali</td>"; }elseif($i <$this->startday){ $ev = ''; $ev .= "<td> </td>"; }else{ $ev = ''; $ev .= "<td align='center' bgcolor='white'>$cali</td>"; } } $output .= $ev; if(($i % 7) == 6) $output .= "</tr>\n"; } $output .= '</table>'; unset($calendar); return $output; } } $cal = new Calendar('03', '2014'); $cal->addEvent(new DateTime('2014-03-12'), new DateTime('2014-03-15'), 'Testing 1'); $cal->addEvent(new DateTime('2014-03-17'), new DateTime('2014-03-19'), 'Testing 2'); $cal->addEvent(new DateTime('2014-03-20'), new DateTime('2014-03-22'), 'Testing 3'); echo $cal->printCalendar(); ?>
  8. Can someone set me off in the right direction please. I'm trying to create an availability calendar by importing dates from an ical file. Basically I'm trying to export booked dates from an airbnb listing and show them on a custom calendar on a personal website. Thanks in advance.
  9. Good Afternoon All, I have set out to create a script which will hopefully add an event to an existing google calendar (as a background process using details recorded during the completion of a form) the script to initalise on the submission of the form. However, I have been unable to achieve any results whilst working on this task, I have only witnessed blank screens. Perhaps I am doing something wrong? Can you help? The required steps: 1. user completes form including date from & date to. 2. user clicks submit 3. onclick(); starts php script 4. php script takes the dates as variables 5. php script uses the predefined google account username and password to authenticate 6. User returns to homepage (Google event added) This is my code so far: (removed ID's for privacy) <?php error_reporting(E_ALL); require_once 'google-api-php-client/src/Google_Client.php'; require_once 'google-api-php-client/src/contrib/Google_CalendarService.php'; session_start(); if ((isset($_SESSION)) && (!empty($_SESSION))) { echo "There are cookies<br>"; echo "<pre>"; print_r($_SESSION); echo "</pre>"; } // This is the file I am using ,,, i have cut out the ID's for privacy $client = new Google_Client(); $client->setApplicationName("Google Calendar PHP Starter Application"); $client->setClientId('MY CLI ID HERE'); $client->setClientSecret('MY CLI SECRECT KEY HERE'); $client->setRedirectUri('http://localhost/index.php'); $client->setDeveloperKey('MY API KEY HERE'); $cal = new Google_CalendarService($client); if (isset($_GET['logout'])) { echo "<br><br><font size=+2>Logging out</font>"; unset($_SESSION['token']); } if (isset($_GET['code'])) { echo "<br>I got a code from Google = ".$_GET['code']; // You won't see this if redirected later $client->authenticate($_GET['code']); $_SESSION['token'] = $client->getAccessToken(); header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); echo "<br>I got the token = ".$_SESSION['token']; // <-- not needed to get here unless location uncommented } if (isset($_SESSION['token'])) { echo "<br>Getting access"; $client->setAccessToken($_SESSION['token']); } if ($client->getAccessToken()){ echo "<hr><font size=+1>I have access to your calendar</font>"; $event = new Google_Event(); $event->setSummary('Halloween'); $event->setLocation('The Neighbourhood'); $start = new Google_EventDateTime(); $start->setDateTime('2013-9-29T10:00:00.000-05:00'); $event->setStart($start); $end = new Google_EventDateTime(); $end->setDateTime('2013-9-29T10:25:00.000-05:00'); $event->setEnd($end); $createdEvent = $cal->events->insert('###', $event); echo "<br><font size=+1>Event created</font>"; echo "<hr><br><font size=+1>Already connected</font> (No need to login)"; } else { $authUrl = $client->createAuthUrl(); print "<hr><br><font size=+2><a href='$authUrl'>Connect Me!</a></font>"; } $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; echo "<br><br><font size=+2><a href=$url?logout>Logout</a></font>"; ?> <html></html> Here's a video demonstration I created: http://www.youtube.com/watch?v=m3N4YbqiYR8 Many Thanks for reading and future contributions towards helping me. Josh
  10. Hello all, I just have to start by saying i am very much new to PHP. Iv only done basic things but would really like to learn more. I am also new to forums so please try see past my "not so bright" moments and help. I have to build a interactive calendar. People who visit the website will select days they would like to rent the flat for. This will then make those dates unavailable for other people, so they shouldnt be able to select it. The cost of the flat will change according to date (Jan-dec : December being more expensive for christmas etc.) Rates will also influence the cost. Is there some sort of tutorial or site i could visit that will show me how to do this? Or does any one maybe know how to help me? I am quite despirate for help and information. Being the noob isnt exactly awesome. Please, please, please help me - Anything will help
  11. I am making a php calendar but struggling to get the query to work. The php calendar is made through a function with 3 variables fed into it. you can find the full calendar http://davidwalsh.name/php-event-calendar Anyway back to my variables. 3 of them.... $month, $year, $events Which are gotten as so.... /* date settings */$month = (int) ($_GET['month'] ? $_GET['month'] : date('m'));$year = (int) ($_GET['year'] ? $_GET['year'] : date('Y')); /* get all events for the given month */$events = array();mysql_select_db($database_dbconnect, $dbconnect);$query = "SELECT title,idcalendar, DATE_FORMAT(event_date,'%Y-%m-%D') AS event_date FROM calendar WHERE event_date LIKE '$year-$month%'";$result = mysql_query($query, $dbconnect) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) {$events[$row['event_date']][] = $row;} Now I have my 3 vars I feed them into my function with the following line <?php echo draw_calendar($month,$year,$events); ?> Now within my function there is the following line to print out the event on any given day /* list the events */if(isset($events[$event_day])) {foreach($events[$event_day] as $event) {$calendar.= '<div class="event">'.$event['title'].'</div>'; }}else {$calendar.= str_repeat('<p> </p>',2);} As you can see if it finds an event it will show it and if it cant it will show 2 empty paragraph tags. I have an event in my database and under the field titled event_date and the event is for 2013-07-16 00:00:00 which is obviously today. If I use MySQL to run the query it pulls back my event quite happy. As soon as I run it in the webpage I get my empty paragraph tags back. Please help
  12. I am working on a event calendar thingy. I already can read, write, delete, etc. Only issue is, is that I want to echo them in order of coming up next, instead of the order I have saved (xml). Anyone have any suggestions? Extra Info: I loop through all the entries in the xml file to get the event.
  13. Heya Guys, Im hoping someone can help me or point me in the right direction for the following; I am currently building a reservations system fro a friend and the admin area works a treat, I downloaded myEvent Calendar in the hope this would forfill the calendar aspect of the admin area for each cottage but im finding it hard knowing how to link the mysql data into the existing framework for the myEvents Calendar? I have data to be rendered from mysql which I originally thought would nicely pump the variables etc into the section on the code but as its being called from a function im not sure how id get it to work. i really hope someone can help as its driving me around the twist. please see below for example code: THIS IS A Snippet From THE CALENDAR PAGE: <? require("myEventsCalendar.php"); $thisCal = new MyEventsCalendar("/details.php"); $thisCal->setOverlibPath("/overlib.js"); $todaysDate = date("d") . "-" . date("m") . "-" . date("Y"); $sqlCommand = "SELECT * FROM reservations"; $query = mysqli_query($connection, $sqlCommand) or die (mysqli_error()); $reservationDisplay = ''; while ($row = mysqli_fetch_array($query)) { $reservationid = $row["id"]; $propertyname = $row["propertyname"]; $checkindate = $row["checkindate"]; $checkoutdate = $row["checkoutdate"]; $checkintime = $row["checkintime"]; $checkouttime = $row["checkouttime"]; $customerref = $row["customerref"]; $duration = $row["duration"]; $pets = $row["pets"]; $f = $thisCal->addEvent; $newcheckinDate = preg_replace("/(\d+)\D+(\d+)\D+(\d+)/","$3-$2-$1",$checkindate); $reservationDisplay .= '' .$f. '(date(' .$newcheckinDate. '),"Holiday Let Reservation, Mill Wheel </br> Bob Johnson Family </br> 01933 526655","10:45 AM","Reservation for 5 days");'; } mysqli_free_result($query); $reservationDisplay; <?php /*?>i was hoping that this variable would pump out what was required below<?php */?> $thisCal->addEvent(date($newcheckinDate), "Holiday Let Reservation, Mill Wheel </br> Bob Johnson Family </br> 01933 526655", "10:45 AM", "Reservation for 5 days"); $thisCal->addEvent(date("03") . "-" . date("10") . "-" . date("2013"), "Holiday Let Reservation, Mill Wheel </br> Bob Johnson Family </br> 01933 526655", "10:45 AM", "Reservation for 5 days"); if($_GET["m"] && $_GET["y"]) { $thisCal->setMonth(trim($_GET["m"])); $thisCal->setDay(1); $thisCal->setYear(trim($_GET["y"])); $thisCal->generateHTML("adminhome.php?calendar=start"); } else { $thisCal->setMonth(date("m")); $thisCal->setDay(1); $thisCal->setYear(date("Y")); $thisCal->generateHTML("adminhome.php?calendar=start"); } ?> =========Here is the MyEventsCalendar Page with the relevent functions etc===================== Sorry for the long page etc <?php /* * myEventsCalendar Class * **/ class myEventsCalendar { var $month = 0, $day = 0, $year = 0; var $Months = Array("January", "February","March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); var $overlibPath = "", $eventsId = array(), $eventsData = array(), $eventsCount = 0; var $formDetailsAction = ""; function myEventsCalendar($thisFormDetailsAction) { //set the destination to view event detail $this->formDetailsAction = $thisFormDetailsAction; //set additional parameters if necessary //need to set month, day, and year //before generating HTML $this->eventsData = array(); $this->eventsCount = count($this->eventsData); } /**Append the parameter element to the vector*/ function addEvent($thisDate,$thisEventTitle, $thisEventTime, $thisEventDescription) { if(!empty($thisDate)) { $dateArr = explode("-",$thisDate); $mIndex = intVal($dateArr[0]); $dIndex = intVal($dateArr[1]); $yIndex = intVal($dateArr[2]); $dateIndex = $mIndex . "-" . $dIndex . "-" . $yIndex; if(!$this->eventsId[$dateIndex]) { $this->eventsId[$dateIndex] = 1; } else { $numOfEvents = intVal($this->eventsId[$dateIndex]); $numOfEvents = $numOfEvents + 1; $this->eventsId[$dateIndex] = $numOfEvents; } $titleIdx = "title" . $this->eventsId[$dateIndex]; $timeIdx = "time" . $this->eventsId[$dateIndex]; $descrIdx = "description" . $this->eventsId[$dateIndex]; $this->eventsData[$dateIndex][$titleIdx] = $thisEventTitle; $this->eventsData[$dateIndex][$timeIdx] = $thisEventTime; $this->eventsData[$dateIndex][$descrIdx] = $thisEventDescription; $this->eventsCount = count($this->eventsData); return true; } else return false; } function setMonth($thisMonth) { $this->month = $thisMonth; } function setYear($thisYear) { $this->year = $thisYear; } function setDay($thisDay) { $this->day = $thisDay; } function setOverlibPath($thisPath) { $this->overlibPath = $thisPath; } function getDayOfMonth($month, $day, $year) { $myresult = date("l", mktime(0, 0, 0, $month, $day, $year)); return $myresult; } function getMonthName($month, $day, $year) { $myresult = date("F", mktime(0, 0, 0, $month, $day, $year)); return $myresult; } function getWeekDay($day) { $myresult = 0; switch ($day) { case "Monday": $myresult = 1; break; case "Tuesday": $myresult = 2; break; case "Wednesday": $myresult = 3; break; case "Thursday": $myresult = 4; break; case "Friday": $myresult = 5; break; case "Saturday": $myresult = 6; break; case "Sunday": $myresult = 7; break; } return $myresult; } function getNumDaysOfMonth($month, $year) { // non-leap year $nonleap = Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); // leap year $leap = Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $isLeap = false ; if (($year % 4) == 0) { if (($year % 100) == 0 && ($year % 400) != 0) { $isLeap = false; } else { $isLeap = true; } } else { $isLeap = false; } if($isLeap == true) { return $leap[$month - 1]; } else { return $nonleap[$month - 1]; } } function isToday($month,$day,$year) { if( ($month == intval(date("m"))) && ( $day == intval(date("d"))) && ($year == intval(date("Y")))){ return true; } else { return false; } } //Some book keeping function getDetails($thisDate, $allDetails) { $counter = 1; $titleIdx = "title" . $counter; $timeIdx = "time" . $counter; $descrIdx = "description" . $counter; $result = ""; //prepare overlib data while($this->eventsData[$thisDate][$titleIdx] != "") { if($counter > 1){ $result .= "<br><br>"; } $result .= "<b>Reservation Details:</b> " . $this->eventsData[$thisDate][$titleIdx]; $result .= "<br><b>Check in Time:</b> " . $this->eventsData[$thisDate][$timeIdx]; if($allDetails) { $result .= "<br><b>Summary:</b> " . $this->eventsData[$thisDate][$descrIdx]; } $counter = $counter + 1; $titleIdx = "title" . $counter; $timeIdx = "time" . $counter; $descrIdx = "description" . $counter; } return $result; } //This function takes the parameters month, day, and year and //queries the global array with the event information for any //relevant events that occur on that date function outputDay($thisMonth,$thisDay,$thisYear) { $thisDate = $thisMonth . "-" . $thisDay . "-" . $thisYear; if($this->eventsId[$thisDate]) { $overlib = $this->getDetails($thisDate, false); $details = $this->getDetails($thisDate, true); echo "<table style='background-color:#006699;' width='40' height='40' border='0' cellspacing='0' cellpadding='2'> <tr> <td><div class='Reservation'><a style='background-color:#006699; color:#fff; font-weight:bold; height:40px; width:40px;' href=\"javascript:goToDetails('" . urlencode($details) . "')"; echo ";\" "; echo "onmouseover=\"return overlib('" . $overlib . "',"; echo "CAPTION,"; echo "'" . $thisDate . "');\" "; echo "onmouseout=\"return nd();\">". $thisDay ."</a>\n</div></td> </tr> </table>"; } else { echo $thisDay; } } //This function loops through the days available in the month and //outputs each day accordingly. If an event is found, then it will //add a link for that day which shows a preview on an overlib effect, // and upon click, it takes the user to the corresponding details page function generateHTML($toUrl) { //configure top navigation $nextMonth = $this->month + 1; $nextYear = $this->year; if($nextMonth == 13) { $nextMonth = 1; $nextYear = $this->year + 1; } $prevMonth = $this->month - 1; $prevYear = $this->year; if($prevMonth == 0) { $prevMonth = 12; $prevYear = $this->year - 1; } //output overlib js path echo "<script type=\"text/javascript\" src=\"" . $this->overlibPath . "\"></script>"; //output overlib div echo "<div class='EventOverlay' id=\"overDiv\" style=\"position:absolute; visibility:hidden; z-index:1000;\"></div>"; //output detail form echo "<form name=\"jump_to_details\" action=\"" . $this->formDetailsAction . "\" "; echo "method=\"POST\">\n"; echo "<input type=\"hidden\" name=\"event\" value=\"\">\n"; echo "</form>"; //output javascript submit form (handler) method echo "<script language=\"Javascript\">\n"; echo "\n"; echo "function goToDetails(thisEvent) {\n"; echo "document.jump_to_details.event.value=thisEvent\n"; echo "document.jump_to_details.submit()\n"; echo "}\n"; echo "</script>\n"; //configure bottom navigation $gobackwards = $toUrl . "&m=" . $prevMonth . "&y=" . $prevYear; $goforward = $toUrl . "&m=" . $nextMonth . "&y=" . $nextYear; echo "<div class='CalendarHolder' style='background-color:#f3f3f3; border: 2px solid #ccc; padding:4px; border-radius:6px; width:400px;'>"; echo "<div class='CottageTitle'"; echo "<h2>Mill Wheel Cottage Reservations Calendar</h2>"; echo "</div>"; echo "<small>"; echo "<table style='background-color:#f3f3f3; padding:10px;' cellpadding=\"10\">\n"; echo "<tr>\n"; echo " <td colspan=\"7\">"; echo " <table style='background-color:#fff; border: 1px solid #ccc; padding:10px;' cellpadding=\"0\" width=\"100%\">\n"; echo " <tr>\n"; echo " <td width=\"5%\"><a href=\"" . $gobackwards . "\"><img src='/Template/images/Previous.jpg' width='50' height='50' alt='Previous Month' /></a></td>\n"; echo " <td width=\"90%\" align=\"center\"><b style='font:Arial, Helvetica, sans-serif; font-size:16px; color:#333; text-align:center'>" . $this->getMonthName($this->month , 1 , $this->year) . " " . $this->year . "</b></td>\n"; echo " <td width=\"5%\"><a href=\"" . $goforward . "\"><img src='/Template/images/Next.jpg' width='50' height='50' alt='Previous Month' /></a></td>\n"; echo " </tr>\n"; echo " </table>\n"; echo " </td>"; echo "</tr>\n"; echo "<tr>\n"; echo " <td style='background-color:#fff;'><b>Sun</b></td>\n"; echo " <td style='background-color:#fff;'><b>Mon</b></td>\n"; echo " <td style='background-color:#fff;'><b>Tue</b></td>\n"; echo " <td style='background-color:#fff;'><b>Wed</b></td>\n"; echo " <td style='background-color:#fff;'><b>Thu</b></td>\n"; echo " <td style='background-color:#fff;'><b>Fri</b></td>\n"; echo " <td style='background-color:#fff;'><b>Sat</b></td>\n"; echo "</tr>\n"; $newrow = 1; $monLoop = $this->getNumDaysOfMonth($this->month, $this->year); $startDay = intval($this->getWeekDay($this->getDayOfMonth( $this->month, 1, $this->year))); $begin = false; for($i=1; $i <= $monLoop; $i++) { if($startDay == 7) { $begin = true; } if($newrow == 8 || $newrow == 1) { echo "<tr style='background-color:#fff; padding:0px;'>"; $newrow = 1; } if($begin == true) { if( $this->isToday($this->month, $i, $this->year)) { echo " <td><font color=\"red\">"; $this->outputDay(intVal($this->month), intVal($i), intVal($this->year)); echo "</font></td>"; } else { echo " <td>"; $this->outputDay(intVal($this->month), intVal($i), intVal($this->year)); echo "</td>"; } } if($i <= $startDay && $begin == false ) { echo " <td> </td>"; if($i == $startDay) { $begin = true; $i = 0; } } $newrow++; if($newrow == { echo "</tr>"; } } echo "</table>\n"; echo "</small>"; echo "</div>"; } } ?>
  14. Hey guys! I am making an internal booking system for a company, and they requested if I could make a calendar, kind of. Something like this: Instead of this: Any ideas? Thanks.
  15. I have a problem here, this script works with the exception of showing the correct days with the date Result can be seen at https://centurionphotographer.co.za/booking/ AI just gives me one different problem after another and I am not a good enough coder to solve the problem. // Number of months to display $monthsToShow = 3; // Get the current date and time $currentDate = date('Y-m-d'); // Calculate the start and end dates for the calendar $startDate = date('Y-m-d', strtotime($currentDate)); $endDate = date('Y-m-d', strtotime($currentDate . ' + ' . ($monthsToShow * 30) . ' days')); // Prepare the SQL statement to retrieve availability $availabilityQuery = $pdo->prepare(" SELECT avdate, COUNT(*) AS available_slots FROM availability WHERE avdate BETWEEN :start_date AND :end_date GROUP BY avdate "); // Prepare the SQL statement to retrieve bookings $bookingsQuery = $pdo->prepare(" SELECT bkdate, COUNT(*) AS booked_slots FROM bookings WHERE bkdate BETWEEN :start_date AND :end_date GROUP BY bkdate "); // Generate the calendar $currentMonth = ''; echo '<table>'; // Loop through each day within the specified range for ($date = $startDate; $date <= $endDate; $date = date('Y-m-d', strtotime($date . ' + 1 day'))) { $currentMonthOfDate = date('F Y', strtotime($date)); $dayOfWeek = date('w', strtotime($date)); // Check if a new month has started if ($currentMonth !== $currentMonthOfDate) { $currentMonth = $currentMonthOfDate; echo '<tr><th colspan="7">' . $currentMonth . '</th></tr>'; echo '<tr><th>Sunday</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th></tr>'; } // Check availability for the current date $availabilityQuery->bindParam(':start_date', $date); $availabilityQuery->bindParam(':end_date', $date); $availabilityQuery->execute(); $availabilityResult = $availabilityQuery->fetchAll(PDO::FETCH_ASSOC); // Check bookings for the current date $bookingsQuery->bindParam(':start_date', $date); $bookingsQuery->bindParam(':end_date', $date); $bookingsQuery->execute(); $bookingsResult = $bookingsQuery->fetchAll(PDO::FETCH_ASSOC); // Determine the class to apply based on availability if ($availabilityResult && $availabilityResult[0]['available_slots'] > 0) { $class = 'available'; $link = '<a href="timeslots.php?date=' . $availabilityResult[0]['avdate'] . '">Check available timeslots</a>'; } elseif ($bookingsResult && $bookingsResult[0]['booked_slots'] > 0) { $class = 'fully-booked'; $link = 'Fully Booked'; } else { $class = 'unavailable'; $link = ''; } // Output the date with the appropriate class and link echo '<td class="' . $class . '">' . $date . '<br>' . $link . '</td>'; // Start a new row after Saturday if ($dayOfWeek == 6) { echo '</tr><tr>'; } } echo '</table>';
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.