Hi,
I’m using a calendar script (mod_minical) within joomla.
I’m working on a mod of the calendar to pull info from a db to display how many rooms are available within each day of the calendar.
Below is the code I have within the output for each day of the calendar. The code works, the math is right, etc, but it only displays for one month. Eg, I have a room booked in march and may in the db, but the booking info is only reflected in march.
Hey man,
So I have a php calendar script that someone wrote. I’m trying to pull info from a db to show rooms booked for each day.
The calendar script is a fairly simple for($i=0, $i=$somevariable, $i++) type deal. My code is within this for loop, so something like:
//calendar script for each day (there’s more in the script, trying to keep this simple…)
for($i=0, $i=$somevariable, $i++) {
$today=$variable that outputs each day per month
//my code
for( $i=0; $i<$number of records from db; $i++ ){
$datefrom = "from" date (the dates included in the booking - all in yearmonthday format, eg 20130101 for jan, 1, 2013)
$dateto = "to" date
$bookdub = rooms needed within above dates
if (($today>=$datefrom)&&($today<=$dateto)){ (this seems to be where the prob is...)
//add number of rooms needed when $today falls within any dates
$bookdub = $bookdub+$bookdub-$bookdub;
}else{
$bookdub = 0;
}
}
//end of my code - beginning of calendar script output:
}
echo ‘
//end
Below is the full code for the calendar, including my mod.
Thanx a ton for any help you can provide!!!
Mark
[php]
<?php /******************************************************************** Product : Simple Calendar Author : tamim84 Copyright : Tamim Mostafa 2013 Licence : GNU General Public License Description: Displays a calendar in a given module position *********************************************************************/ defined('_JEXEC') or die('Restricted access'); //------------------------------------------------------------------------------- // Define cal_days_in_month() in case server doesn't support it // if (!function_exists('cal_days_in_month')) { function cal_days_in_month($calendar,$month, $year) { return date('t', mktime(0, 0, 0, $month+1, 0, $year)); } } //--------------------------------------------------------------------------------------------- // Get an array of day names in the current language // function get_day_names($start_day) { $j_days = array(JText::_('SUNDAY'),JText::_('MONDAY'),JText::_('TUESDAY'),JText::_('WEDNESDAY'),JText::_('THURSDAY'),JText::_('FRIDAY'),JText::_('SATURDAY')); for ($i = 0; $i < 7; $i++) { $day = ($i + $start_day) % 7; $days[] = $j_days[$day]; } return $days; } //--------------------------------------------------------------------------------------------- // Get a month name in the current language // function get_month_name($month) { switch ($month) { case 1: return JText::_('JANUARY'); case 2: return JText::_('FEBRUARY'); case 3: return JText::_('MARCH'); case 4: return JText::_('APRIL'); case 5: return JText::_('MAY'); case 6: return JText::_('JUNE'); case 7: return JText::_('JULY'); case 8: return JText::_('AUGUST'); case 9: return JText::_('SEPTEMBER'); case 10: return JText::_('OCTOBER'); case 11: return JText::_('NOVEMBER'); case 12: return JText::_('DECEMBER'); } } //--------------------------------------------------------------------------------------------- // Draw a calendar for one month in any language // $link is blank for no links, or a url ready to append 'p' for previous or 'n' for next // function make_calendar($year, $month, $link = '', $day_name_length, $start_day, $weekHdr, $debug=false) { $pid = $_GET["pid"]; $db = JFactory::getDbo(); $query = "SELECT property_id, dub_rooms, sing_rooms, date_from, date_to, dub_rooms_max, sing_rooms_max FROM #__xxxxxxxxxx WHERE `property_id` = $pid"; $db->setQuery($query); $rows = $db->loadObjectList(); $numrows = count($rows); echo $numrows; //print_r($rows); //echo $rows[3]->dub_rooms; $current_year = date('Y'); $current_month = date('m'); $current_day = date('d'); $num_columns = 7; // without week numbers, we have 7 columns if (($weekHdr != '') and ($start_day == 1) and (!stristr(PHP_OS, 'WIN'))) $num_columns = 8; else $weekHdr = ''; // if start day not Monday, or we are on Windows, don't do week numbers echo "\n".''; if ($link != '') echo '« '; $month_string = get_month_name($month).' '.$year; echo $month_string; if ($link != '') echo ' »'; echo ' | '; echo '||
---|---|---|
".$weekHdr." | "; $days = get_day_names($start_day); for ($i = 0; $i < 7; $i++) { $day_name = $days[$i]; if (function_exists('mb_substr')) $day_short_name = mb_substr($day_name,0,$day_name_length,'UTF-8'); // prefer this if available else $day_short_name = substr($day_name,0,$day_name_length); // use this if no mbstring library echo "$day_short_name | "; } echo '|
'.$weeknumber.' | '; } for ($i = 0; $i < $first_column; $i++) echo ''; $column_count = $first_column; for ($day = 1; $day <= $days_in_month; $day++) { if (strlen($day) == 1) { $newday = "0".$day; }else{ $newday = $day; } $monthday = $month.$newday; if ($column_count == 7) { echo " | |
'.$weeknumber.' | '; } } //////////////////////////////////////////////////////////////// $maxdub = $dubrooms; $maxsing = $singrooms; $today = $year.$month.$newday; for( $i=0; $i<$numrows; $i++ ){ $datefrom = str_replace("-", "", $rows[$i]->date_from); $dateto = str_replace("-", "", $rows[$i]->date_to); //echo "today = ".$today; //echo "
'.$newday.' df='.$bookdub.' | ';
$column_count ++;
}
for ($i = $column_count; $i < 7; $i++)
echo ''; echo " |