probs with multiple condition statement in calendar script

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 ‘

’.$newday.‘
rooms booked for today=’.$bookdub.’’;
//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".''."\n"; echo "\n"; // draw the month and year heading in the current language echo ''; echo ''; // draw the day names heading in the current language if ($day_name_length > 0) { echo "\n"; if ($weekHdr != '') echo ""; $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 ""; } echo ''; } // draw the days $bookedfrom = 20130321; $bookedto = 20130508; $dayfrom = substr($bookedfrom,-2); $dayto = substr($bookedto,-2); $bookedyear = substr($bookedfrom,0,4); $bookedmonthfrom = substr($bookedfrom,-4); $bookedmonthto = substr($bookedto,-4); $maxdubrooms = $_GET["dubrooms"]; $maxsingrooms = $_GET["singrooms"]; //echo "pid = ".$pid." dubrooms = ".$dubrooms." singrooms = ".$singrooms; //$bookedrows = $db->loadObjectList(); $day_time = gmmktime(5,0,0,$month,1,$year); // GMT of first day of month if ($debug) mc_trace("\nStart: ".gmstrftime("%Y-%m-%d %H:%M (wk %V)",$day_time)); $first_weekday = gmstrftime("%w",$day_time); // 0 = Sunday ... 6 = Saturday $first_column = ($first_weekday + 7 - $start_day) % 7; // column for first day $days_in_month = cal_days_in_month(CAL_GREGORIAN,$month,$year); echo ''; if ($weekHdr != '') { $weeknumber = gmstrftime("%V",$day_time); // first week number (doesn't work on Windows) echo ''; } 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 "\n"; $column_count = 0; if ($weekHdr != '') { // $day_time = strtotime(strftime('%Y-%m-%d',$day_time).' + 1 week'); $day_time += 604800; // add exactly one week if ($debug) mc_trace(" next week: ".gmstrftime("%Y-%m-%d %H:%M (wk %V)",$day_time)); $weeknumber = gmstrftime("%V",$day_time); // week number echo ''; } } //////////////////////////////////////////////////////////////// $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 "
dfrom = ".$datefrom; //echo "
dto = ".$dateto; //echo "
............
"; if (($today>=$datefrom)&&($today<=$dateto)){ //echo "today= ".$today; $bookdub = $bookdub+$rows[$i]->dub_rooms-$bookdub; }else{ $bookdub = 0; } } ///////////////////////////////////////////////////////////////// echo ''; $column_count ++; } for ($i = $column_count; $i < 7; $i++) echo ''; echo ""; echo ""; echo date('H:i, jS F Y'); echo "
'; if ($link != '') echo '«  '; $month_string = get_month_name($month).' '.$year; echo $month_string; if ($link != '') echo '  »'; echo '
".$weekHdr."$day_short_name
'.$weeknumber.'
'.$weeknumber.'
'.$newday.'
df='.$bookdub.'
\n"; } function mc_init_debug() { $locale = setlocale(LC_ALL,0); $langObj = JFactory::getLanguage(); $version = new JVersion(); $xml_array = JApplicationHelper::parseXMLInstallFile(JPATH_ROOT.'/modules/mod_minicalendar/mod_minicalendar.xml'); mc_trace("\nSimple Calendar ver : ".$xml_array['version']); mc_trace("PHP version : ".phpversion()); mc_trace("PHP Locale : ".print_r($locale, true)); mc_trace("Server : ".PHP_OS); mc_trace("Joomla Version : ".$version->RELEASE.".".$version->DEV_LEVEL); mc_trace("Joomla Language : ".$langObj->get('tag')); } function mc_trace($data) { @file_put_contents(JPATH_ROOT.'/modules/mod_minicalendar/trace.txt', $data."\n",FILE_APPEND); } [/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service