Hi,
I have this script which checks if the current date is between specified dates.
This is for template selection. think of holidays/seasons/birthdays/partyweeks etc.
I have asked for help in newb section but figured it out.
The problem is that i am not happy with it. It too loggy! Can someone take a look, have an idea 😛
<?php
include("db/dbinf.php");
function theme_getstyle()
{
##get current dates
$curdatem = date(m);
$curdated = date(d);
## Make array for first entry grab
$theme_entrys = array();
##make array for final themename
$theme_name = array();
## Get SQL query ready
$theme_sql = mysql_query("SELECT * FROM db_tpl_themes") or die(mysql_error());
while($theme_resultbank=mysql_fetch_array($theme_sql))
{
## Fill array with mapnames to Get first entry (Standard)
$theme_entrys[] = $theme_resultbank['theme_map'];
##Make array for date functions, and clear
unset($theme_posdate);
$theme_posdate = array();
## Get first standard (No dates) and not actives
if($theme_resultbank['theme_force']!='2' AND $theme_resultbank['id']!='1')
{
##Create array for begin < End
if($theme_resultbank['theme_begindate'] >= $theme_resultbank['theme_enddate'])
{
$theme_a = substr($theme_resultbank['theme_begindate'], 0,2);
$a = $theme_a;
while($a <= '12')
{
$theme_posdate[$a] = $a;
$a++;
}
$theme_b = substr($theme_resultbank['theme_enddate'], 0,2);
$b = '1';
while($b <= $theme_b)
{
$theme_posdate[$b] = $b;
$b++;
}
}
##Create array for begin > End
elseif($theme_resultbank['theme_begindate'] <= $theme_resultbank['theme_enddate'])
{
$theme_c = substr($theme_resultbank['theme_enddate'], 0,2) - substr($theme_resultbank['theme_begindate'], 0,2);
$c = substr($theme_resultbank['theme_begindate'], 0,2);
$d = $c+$theme_c;
while($c <= $d)
{
$theme_posdate[$c] = $c;
$c++;
}
}
## Time to check if current date is in the array
if(in_array($curdatem, $theme_posdate))
{
$theme_begindatem = substr($theme_resultbank['theme_begindate'], 0,2);
$theme_enddatem = substr($theme_resultbank['theme_enddate'], 0,2);
$theme_begindated = substr($theme_resultbank['theme_begindate'], -2,2);
$theme_enddated = substr($theme_resultbank['theme_enddate'], -2,2);
##Check if the date matches with either begin or enddate.
## If so check on day scale
if($theme_begindatem == $curdatem OR $theme_enddatem == $curdatem)
{
##Check if the day is bigger than beginday or smaller than endday
if($theme_begindatem == $curdatem AND $theme_begindated <= $curdated)
{
$theme_name[] = $theme_resultbank['theme_map'];
}
elseif($theme_enddatem == $curdatem AND $theme_enddated >= $curdated)
{
$theme_name[] = $theme_resultbank['theme_map'];
}
## Not okaj? No fill in theme_name. First entry will be auto selected
}
else
{
##Date is in array but not begin or enddate, it ok then
$theme_name = $theme_resultbank['theme_map'];
}
}
}
}
## Check if theme_name is found, if not subsitute with first entry
if($theme_name)
{
print $theme_name[0];
}
else
{
print $theme_entrys[0];
}
}
?>
Link to prev post: Link to newb post