Hey everyone!
Have got a PHP Diary Script that i'm trying to edit, currently on the main diary view for each day it displays the Time (if 1 is set) and description as well as sets the font colour depending on the Category. I am trying to make it also display the Category Name at the beginning of each event so it goes "Category Name, Time, Description" but am having problems so far trying to do this.
The bottom half of the page PHP Code is below:
<?php if($CalendarOptions["showCategories"]=="true"){ ?>
<table width="100%" cellspacing="0" cellpadding="0" style="background-color:#<?php echo $CalendarOptions["headerBGColor"]; ?>;">
<tr>
<td style="padding:5px;">
<?php
$sql = "SELECT * FROM ".$TABLES["Categories"]." WHERE id > 1 AND calendar_id = '".SaveToDB($_REQUEST["cid"])."' ORDER BY id ASC";
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
$categoryCount = mysql_num_rows($sql_result);
$colWidth = floor(100/($categoryCount+3));
$bufferWidth = floor((100 - ($categoryCount+1)*$colWidth) / 2);
?>
<div style="<?php echo $fontFamily; ?> padding:3px 15px 3px 15px; background-color:#<?php echo $CalendarOptions["allCategoriesBGColor"]; ?>; float:left; margin-right:5px; cursor:pointer; text-decoration:none; text-align:center; color:#<?php echo oppColor($CalendarOptions["allCategoriesBGColor"]); ?>; font-size:<?php echo $FontSize[$CalendarOptions["categoriesFontSize"]]; ?>px; white-space:nowrap; <?php echo $Styles[$CalendarOptions["categoriesFontStyle"]]; ?>" onclick="javascript:ajaxpage('<?php echo $SETTINGS["installFolder"]."load-calendar.php?month=". ($cMonth*1) . "&year=" . $cYear. "&cid=".$_REQUEST["cid"]; ?>&catid=0','MonthlyCalendar','get');"><?php echo $PHP_MONTHLY_LANG["AllCategoeis"]; ?></div>
<?php
while ($Category = mysql_fetch_assoc($sql_result)) {
?>
<div style="<?php echo $fontFamily; ?> padding:3px 15px 3px 15px; background-color:#<?php echo $Category["category_color"]; ?>; float:left; margin-right:5px; cursor:pointer; text-decoration:none; text-align:center; color:#<?php echo oppColor($Category["category_color"]); ?>; font-size:<?php echo $FontSize[$CalendarOptions["categoriesFontSize"]]; ?>px; white-space:nowrap; <?php echo $Styles[$CalendarOptions["categoriesFontStyle"]]; ?>" onclick="javascript:ajaxpage('<?php echo $SETTINGS["installFolder"]."load-calendar.php?month=". $cMonth . "&year=" . $cYear. "&cid=".$_REQUEST["cid"]; ?>&catid=<?php echo $Category["id"]; ?>','MonthlyCalendar','get');">
<?php echo ReadFromDB($Category["category_name"]); ?>
</div>
<?php
}
?>
</td>
</tr>
</table>
<?php }; ?>
<div style="clear:both">
<?php
$columnFontSize = $FontSize[$CalendarOptions["columnFontSize"]];
$columnFontStyle = $Styles[$CalendarOptions["columnFontStyle"]];
$colStyle = 'style="padding-bottom:3px; padding-left:6px; '.$fontFamily.' font-size:'.$columnFontSize.'px; color:#'.$CalendarOptions["columnFontColor"].'; '.$columnFontStyle.'"';
?>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<?php
if($_REQUEST["catid"]>0) $category = " AND category_id = '".SaveToDB($_REQUEST["catid"])."'";
else $category = "";
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
for ($i=1; $i<$maxday+1; $i++) {
$currDay = date("Y-m-d",mktime(0,0,0,$cMonth,$i,$cYear));
if($CalendarOptions["showCategories"]=="true"){
$sql = "SELECT ".$TABLES["Events"].".*, ".$TABLES["Categories"].".category_name, ".$TABLES["Categories"].".category_color
FROM ".$TABLES["Events"].", ".$TABLES["Categories"]."
WHERE ".$TABLES["Events"].".category_id = ".$TABLES["Categories"].".id
AND ".$TABLES["Events"].".calendar_id = '".SaveToDB($_REQUEST["cid"])."'
AND ".$TABLES["Events"].".event_date = '".$currDay."' " .
$category . "
AND ".$TABLES["Events"].".show_event = 'Show'
ORDER BY event_time ASC";
} else {
$sql = "SELECT * FROM ".$TABLES["Events"]."
WHERE event_date = '".$currDay."'
AND calendar_id = ".SaveToDB($_REQUEST["cid"])."
AND show_event = 'Show'
ORDER BY event_time ASC";
}
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
$rows = mysql_num_rows($sql_result);
if($rows>1) $rowspan = "rowspan='".$rows."'";
else $rowspan = "";
$dayOfWeek = date("w",mktime(0,0,0,$cMonth,$i,$cYear));
switch ($dayOfWeek) {
case 0: $bgColor = $CalendarOptions["sundayBGColor"]; break;
case 1: $bgColor = $CalendarOptions["mondayBGColor"]; break;
case 2: $bgColor = $CalendarOptions["tuesdayBGColor"]; break;
case 3: $bgColor = $CalendarOptions["wednesdayBGColor"]; break;
case 4: $bgColor = $CalendarOptions["thursdayBGColor"]; break;
case 5: $bgColor = $CalendarOptions["fridayBGColor"]; break;
case 6: $bgColor = $CalendarOptions["saturdayBGColor"]; break;
}
if($dayOfWeek==0 or $dayOfWeek==5){
$border = "border-bottom:".$CalendarOptions["weekendBorderSize"]."px solid #".$CalendarOptions["weekendBorderColor"]."; border-right:".$CalendarOptions["innerBorderSize"]."px solid #".$CalendarOptions["innerBorderColor"].";";
$eventBorder = "border-bottom:".$CalendarOptions["weekendBorderSize"]."px solid #".$CalendarOptions["weekendBorderColor"].";";
} else {
$border = "border-bottom:".$CalendarOptions["innerBorderSize"]."px solid #".$CalendarOptions["innerBorderColor"]."; border-right:".$CalendarOptions["innerBorderSize"]."px solid #".$CalendarOptions["innerBorderColor"].";";
$eventBorder = "border-bottom:".$CalendarOptions["innerBorderSize"]."px solid #".$CalendarOptions["innerBorderColor"].";";
}
if($currDay==date("Y-m-d")) $dayColor = $CalendarOptions["currentDateBGColor"];
else $dayColor = $bgColor;
$weekdaysFontSize = $FontSize[$CalendarOptions["weekdaysFontSize"]];
$weekdaysFontStyle = $Styles[$CalendarOptions["weekdaysFontStyle"]];
$eventFontSize = $FontSize[$CalendarOptions["eventFontSize"]];
$eventFontStyle = $Styles[$CalendarOptions["eventFontStyle"]];
$dayStyle = 'style="'. $fontFamily . $border.' color:#'. $CalendarOptions["weekdaysFontColor"].'; font-size:'.$weekdaysFontSize.'px; ' .$weekdaysFontStyle.'; padding-left:5px" bgcolor=#'.$dayColor;
?>
<tr align="left">
<td <?php echo $rowspan; ?> align="right" valign="top" <?php echo $dayStyle; ?> width="5%"><?php echo $i; ?> </td>
<td <?php echo $rowspan; ?> align="left" valign="top" <?php echo $dayStyle; ?> width="10%"><?php echo $Days[$dayOfWeek]; ?> </td>
<?php
if($rows>1){
$rNum = 0;
while($Event = mysql_fetch_assoc($sql_result)){
$show_time = "";
if(ReadFromDB($Event["show_time"])=="1" or ReadFromDB($Event["show_time"])=="3") $show_time = getFormatedTime(ReadFromDB($Event["event_time"])).' - ';
$daylyEvent = $show_time . ReadHTMLFromDB($Event["description"]);
$rNum++;
if($rNum>1) echo "<tr>";
if(ReadFromDB($Event["event_color"])=="") {
if (ReadFromDB($Event["category_id"])>1) {
$Event["event_color"] = ReadFromDB($Event["category_color"]);
} else {
$Event["event_color"] = $CalendarOptions["eventFontColor"];
};
}
if($dayOfWeek==0 or $dayOfWeek==5){
if($rNum!=$rows) $eventBorder = "border-bottom:".$CalendarOptions["innerBorderSize"]."px solid #".$CalendarOptions["innerBorderColor"].";";
else $eventBorder = "border-bottom:".$CalendarOptions["weekendBorderSize"]."px solid #".$CalendarOptions["weekendBorderColor"].";";
}
$eventStyle = 'style="padding-left:6px; ' . $fontFamily . $eventBorder.' color:#'. $Event["event_color"] .'; font-size:'.$eventFontSize.'px; ' .$eventFontStyle.'" bgcolor=#'.$bgColor;
?>
<td align="left" <?php echo $eventStyle; ?>><?php echo $daylyEvent; ?> </td>
</tr>
<?php
}
} else{
$Event = mysql_fetch_assoc($sql_result);
$color = $Event["event_color"];
$show_time = "";
if(ReadFromDB($Event["show_time"])=="1" or ReadFromDB($Event["show_time"])=="3") $show_time = getFormatedTime(ReadFromDB($Event["event_time"])).' - ';
if($rows==1) $daylyEvent = $show_time . ReadHTMLFromDB($Event["description"]);
else $daylyEvent = "";
if(ReadFromDB($Event["event_color"])=="") {
if (ReadFromDB($Event["category_id"])>1) {
$Event["event_color"] = ReadFromDB($Event["category_color"]);
} else {
$Event["event_color"] = $CalendarOptions["eventFontColor"];
};
}
$eventStyle = 'style="padding-left:6px; ' . $fontFamily . $eventBorder.' color:#'. $Event["event_color"].'; font-size:'.$eventFontSize.'px; ' .$eventFontStyle. '" bgcolor=#'.$bgColor;
?>
<td align="left" <?php echo $eventStyle; ?>><?php echo $daylyEvent; ?> </td>
</tr>
<?php
}
?>
<?php
};
?>
</table>
</div>
</td>
</tr>
</table>