Scottmandoo 0 Junior Poster in Training

Ok so heres the site: http://allegro1dancestudio.com/

Ive made an event calendar for that site which uses a flat-file database. The calendar part works fine, however, the code is able to make the file but will not write to it and therefore I dont know if i can even get event info from it.

And also once the cal_events.text file is made I do change the permissions so it is writable.

heres the calendar code

<?php
date_default_timezone_set('Australia/Melbourne');

define("EVENT_FILE", "cal_events.text"); 

// Get values from query string 
$day = $_GET["day"]; 
$month = $_GET["month"]; 
$year = $_GET["year"]; 
$sel = $_GET["sel"]; 
$what = $_GET["what"]; 

if($day == "") 
$day = date("j"); 

if($month == "") 
$month = date("m"); 

if($year == "") 
$year = date("Y"); 

$currentTimeStamp = strtotime("$year-$month-$day"); 
$monthName = date("F", $currentTimeStamp);
$numDays = date("t", $currentTimeStamp); 
$counter = 0; 
$numEventsThisMonth = 0; 
$hasEvent = false; 
$todaysEvents = "";

$arrEvents = ReadEvents($month); 

function ReadEvents($Month) 
{ 
// We will get all of the events for this month into an associative 
// array and that array will then be returned 

$theEvents = array(); 
$eventCounter = 0; 

// Make sure that the file exists 
if(!file_exists($_SERVER["DOCUMENT_ROOT"] . "/" . EVENT_FILE)) 
{ 
$fp = @fopen($_SERVER["DOCUMENT_ROOT"] . "/" . EVENT_FILE, "w") 
or die("<span class='error'>ERROR: Couldn't create events file.</span>"); 
@fclose($fp); 
} 

$fp = @fopen($_SERVER["DOCUMENT_ROOT"] . "/" . EVENT_FILE, "rb") 
or die("<span class='error'>ERROR: Couldn't open events file to read events.</span>"); 

while($data = fread($fp, 1024)) 
{ 
$events .= $data; 
} 

@fclose($fp); 

// Seperate the data into line-seperated arrays 
$arrEvents = explode("\r\n", $events); 

// Loop through the results and pick the arrays 
// that match the selected month 
for($i = 0; $i < sizeof($arrEvents); $i+=3) 
{ 
// Get each part of the events date as an index 
// of an array 
$arrEventDate = explode(" ", $arrEvents[$i]); 

// If the month is the selected month the grab 
// the details of this event 
if((int)$arrEventDate[0] == (int)$Month) 
{ 
$theEvents[$eventCounter++] = array("day" => $arrEventDate[1], "name" => $arrEvents[$i+1], "desc" => $arrEvents[$i+2]); 
} 
} 

return $theEvents; 

foreach($arrEvents as $eventEntry) 
{ 
if($eventEntry["day"] == $i) 
{ 
// We have at least one event for the day 
$hasEvent = true; 
$numEventsThisMonth++; 
}

if($eventEntry["day"] == $day) 
{ 
// Add the event to the $todaysEvents variable 
$todaysEvents .= "<span class='eventTitle'>" . stripslashes($eventEntry["name"]) . "</span>"; 

$todaysEvents .= "<span class='eventDesc'><br>" . stripslashes($eventEntry["desc"]) . "</span><br>"; 
} 
} 
}

?>

<table width='320' border='0' cellspacing='2' cellpadding='0'> 
<tr>
<td colspan="7" align="left" valign="bottom"><div class="event"><?php echo $todaysEvents; ?></div></td>
</tr>
<tr>
<tr>
<td colspan="7" align="right"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="image" src="images/month-prev-2.png" width="30" height="33" onmouseover="this.src='images/month-prev-1.png'" onmouseout="this.src='images/month-prev-2.png'" onClick='goLastMonth(<?php echo $month . ", " . $year; ?>)' /><input type="image" src="images/month-next-2.png" width="30" height="33" onmouseover="this.src='images/month-next-1.png'" onmouseout="this.src='images/month-next-2.png'" onClick='goNextMonth(<?php echo $month . ", " . $year; ?>)' /></td>
<td><div class="month"><?php echo $monthName . "."; ?></div></td>
</tr>
</table></td>
</tr>

<?php
$numDays = date("t", $currentTimeStamp); 

for($i = 1; $i < $numDays+1; $i++, $counter++) 
{ 
$timeStamp = strtotime("$year-$month-$i"); 

if($i == 1) 
{ 
// Workout when the first day of the month is 
$firstDay = date("w", $timeStamp); 

for($j = 0; $j < $firstDay; $j++, $counter++) 
echo "<td height='20'>&nbsp;</td>"; 
} 

if($counter % 7 == 0) 
echo "</tr><tr>"; 

if($i == $day && $month == date("m") && $year == date("Y") && $sel == 1) 
echo "<td height='20' align='center' valign='middle' bgcolor='#A805FF'><strong><a href='?sel=1&day=$i&month=$month&year=$year'><div bg='images/sel.png'>$i</div></a></strong></td>";
else 
if($i == $day && $sel == 1) 
echo "<td height='20' align='center' valign='middle' bgcolor='#A805FF'><strong><a href='?sel=1&day=$i&month=$month&year=$year'><div bg='images/sel.png'>$i</div</a></strong></td>";
else
if($i == date("d") && $month == date("m") && $year == date("Y")) 
echo "<td height='20' align='center' valign='middle' bgcolor='#0084FF'><strong><a href='?sel=1&day=$i&month=$month&year=$year'><div bg='images/today.png'>$i</div></a></strong></td>"; 
else
if($hasEvent == true)
echo "<td height='20' align='center' valign='middle' bgcolor='#FF05E4'><strong><a href='?sel=1&day=$i&month=$month&year=$year'><div bg='images/event.png'>$i</div></a></strong></td>";
else
echo "<td height='20' align='center' valign='middle' bgcolor='#999999'><strong><a href='?sel=1&day=$i&month=$month&year=$year'><div bg='images/normal.png'>$i</div></a></strong></td>";

}

$monthName = date("F", $currentTimeStamp); 
?>

<script type="text/javascript">
function goLastMonth(month, year) 
{ 
// If the month is Januaru, decrement the year 
if(month == 1) 
{ 
--year; 
month = 13; 
} 

document.location.href = '?month='+(month-1)+'&year='+year; 
} 

function goNextMonth(month, year) 
{ 
// If the month is December, increment the year 
if(month == 12) 
{ 
++year; 
month = 0; 
} 

document.location.href = '?month='+(month+1)+'&year='+year; 
} 
</script>
</tr></table>

heres the form i use to input the events

<form id="form1" name="form1" method="get" action="add-event.php">
  <table width="300" border="1" align="center" cellpadding="2" cellspacing="0">
    <tr>
      <td>Event Name:</td>
      <td><label>
        <input type="text" name="name" id="name" />
      </label></td>
    </tr>
    <tr>
      <td>Event Details:</td>
      <td><label>
        <input type="text" name="details" id="details" />
      </label></td>
    </tr>
    <tr>
      <td>Event Date:</td>
      <td>
        <select name="day" id="day">
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
          <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
          <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
          <option value="19">19</option>
          <option value="20">20</option>
          <option value="21">21</option>
          <option value="22">22</option>
          <option value="23">23</option>
          <option value="24">24</option>
          <option value="25">25</option>
          <option value="26">26</option>
          <option value="27">27</option>
          <option value="28">28</option>
          <option value="29">29</option>
          <option value="30">30</option>
          <option value="31">31</option>
        </select>
        <select name="month" id="month">
          <option value="01" selected="selected">January</option>
          <option value="02">February</option>
          <option value="03">March</option>
          <option value="04">April</option>
          <option value="05">May</option>
          <option value="06">June</option>
          <option value="07">July</option>
          <option value="08">August</option>
          <option value="09">September</option>
          <option value="10">October</option>
          <option value="11">November</option>
          <option value="12">December</option>
        </select>
        <input name="year" type="text" id="year" value="2010" size="5" maxlength="4" />
      </td>
    </tr>
    <tr>
      <td colspan="2" align="center"><label>
        <input type="submit" name="submit" id="submit" value="Submit" />
      </label></td>
    </tr>
  </table>
</form>

heres the code i use to add the events to the flat-file

<?php
define("EVENT_FILE", "cal_events.text"); 

$name		= $_GET['name'];
$details	= $_GET['details'];
$day		= $_GET['day'];
$month		= $_GET['month'];
$year		= $_GET['year'];

function AddPost($day, $month, $year, $name, $details) 
{
// Add this event to the events file 
$fp = @fopen($_SERVER["DOCUMENT_ROOT"] . "/" . EVENT_FILE, "a") 
or die("<span class='error'>ERROR: Couldn't open events file to write event.</span>"); 

@fputs($fp, "$month $day $year\r\n$name\r\n$details\r\n") 
or die("<span class='error'>ERROR: Couldn't write to events file.</span>"); 

@fclose($fp);
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.