what is wrong here ?

PHP coding talk.

Moderator: Moderators

what is wrong here ?

Postby Mr-Slowly on Wed Mar 14, 2007 8:41 am

Greetings

i'm using a calendar sript but it does not print all the days
i cant make it work

View here

Code: Select all
<?php
$template->set_filenames(array(
      'calendar' => 'calendar.tpl'
));


$CurDate = getdate();

$YearToShow = $CurDate['year'];
$MonthToShow = $CurDate['mon'];
$DayToShow = $CurDate['mday'];
$NumberOfDays = date(t,mktime(0,0,0,$MonthToShow+1,0,$YearToShow,-1));

$MonthNames = array(1=>'January','February','March','April','May','June','July','August','September','October','November','December');

$template->assign_block_vars('calendar', array(
            'Month_Name' => $MonthNames[$MonthToShow],
            'Year' => $YearToShow
            ));

$FirstDayOfWeek = date(l,mktime(0,0,0,$MonthToShow,1,$YearToShow));

switch ($FirstDayOfWeek) {
   case 'Tuesday':
      $offset = 1;
   break;
   case 'Wednesday':
      $offset = 2;
   break;
   case 'Thursday':
      $offset = 3;
   break;
   case 'Friday':
      $offset = 4;
   break;
   case 'Saturday':
      $offset = 5;
   break;
   case 'Sunday':
      $offset = 6;
   break;
   default:
      $offset = 0;
}

if ($offset > 0) {

$zero_2 = str_repeat("<td class=\"row1\">x</td>\n",$offset);
$template->assign_vars(array(
            'zero_1' => '<tr align="center">',
            'zero_2' => $zero_2
         ));

}

for ($i=1; $i <= $NumberOfDays; $i++) {
   $DayOfWeek = date(l,mktime(0,0,0,$MonthToShow,$i,$YearToShow));
   if($DayOfWeek == 'Monday') {
   $template->assign_vars(array(
            'zero_3' => "<tr align=\"center\">"
         ));
   }
   if ($i != $DayToShow) {
      $template->assign_vars(array(
            'dagen' => "<td class=\"row1\">$i</td>"
         ));

   } else {
      $template->assign_vars(array(
            'dag_i' => "<td class=\"row1\"><span class=\"red\">$i</span></td>\n"
         ));
   }
   if($DayOfWeek == 'Sunday') {
      $template->assign_vars(array(
            'tr_end' => "</tr>\n"
         ));

   }
}

if ( ( ($offset == 5) && ($NumberOfDays > 30) ) || ( ($offset == 6) && ($NumberOfDays > 29) ) ) {
   if (42-$NumberOfDays-$offset > 0) {
      $zero_x = str_repeat("<td class=\"row1\">x</td>\n",42-$NumberOfDays-$offset);
      $template->assign_vars(array(
            'zero_x' => $zero_x
         ));
   }
      $template->assign_vars(array(
            'tr_ends' => "</tr>\n"
         ));

} elseif ( ($NumberOfDays != 28) || ($offset > 0) ) {
   if (35-$NumberOfDays-$offset > 0) {
      $zero_x_2 = str_repeat("<td class=\"row1\">x</td>\n",35-$NumberOfDays-$offset);
      $template->assign_vars(array(
            'zero_x_2' => $zero_x_2,
            'tr_end_2' => "</tr>\n"
         ));
   }
}

$template->pparse('calendar');

?>


tnx in advance :wink:
God Bless You
Mr-Slowly
Registered User
Registered User
 
Posts: 29
Joined: Wed Mar 07, 2007 12:15 pm

Postby Mr-Slowly on Wed Mar 14, 2007 5:03 pm

bump **

this is the real file

Code: Select all
<?php

$CurDate = getdate();

$YearToShow = $CurDate['year'];
$MonthToShow = $CurDate['mon'];
$DayToShow = $CurDate['mday'];
$NumberOfDays = date(t,mktime(0,0,0,$MonthToShow+1,0,$YearToShow,-1));

$MonthNames = array(1=>'January','February','March','April','May','June','July','August','September','October','November','December');

?>
<table width="100%" cellspacing="0" class="forumline">
<tr>
<th colspan="7" align="center"><span><?php echo $MonthNames[$MonthToShow],' ', $YearToShow ;?></span></th>
</tr>
<tr align="center">
<td class="cal">M</td>
<td class="cal">D</td>
<td class="cal">W</td>
<td class="cal">D</td>
<td class="cal">V</td>
<td class="cal">Z</td>
<td class="cal">Z</td>
</tr>

<?php
$FirstDayOfWeek = date(l,mktime(0,0,0,$MonthToShow,1,$YearToShow));

switch ($FirstDayOfWeek) {
   case 'Tuesday':
      $offset = 1;
   break;
   case 'Wednesday':
      $offset = 2;
   break;
   case 'Thursday':
      $offset = 3;
   break;
   case 'Friday':
      $offset = 4;
   break;
   case 'Saturday':
      $offset = 5;
   break;
   case 'Sunday':
      $offset = 6;
   break;
   default:
      $offset = 0;
}

if ($offset > 0) {
   print "<tr align=\"center\">\n";
   echo str_repeat("<td class=\"row1\">x</td>\n",$offset);
}

for ($i=1; $i <= $NumberOfDays; $i++) {
   $DayOfWeek = date(l,mktime(0,0,0,$MonthToShow,$i,$YearToShow));
   if($DayOfWeek == 'Monday') {
      print "<tr align=\"center\">\n";
   }
   if ($i != $DayToShow) {
      print "<td class=\"row1\">$i</td>\n";
   } else {
      print "<td class=\"row1\"><span class=\"red\">$i</span></td>\n";
   }
   if($DayOfWeek == 'Sunday') {
      print "</tr>\n";
   }
}

if ( ( ($offset == 5) && ($NumberOfDays > 30) ) || ( ($offset == 6) && ($NumberOfDays > 29) ) ) {
   if (42-$NumberOfDays-$offset > 0) {
      echo str_repeat("<td class=\"row1\">x</td>\n",42-$NumberOfDays-$offset);
   }
   print "</tr>\n";
} elseif ( ($NumberOfDays != 28) || ($offset > 0) ) {
   if (35-$NumberOfDays-$offset > 0) {
      echo str_repeat("<td class=\"row1\">x</td>\n",35-$NumberOfDays-$offset);
   print "</tr>\n";
   }
}

print "</table>\n";
?>
God Bless You
Mr-Slowly
Registered User
Registered User
 
Posts: 29
Joined: Wed Mar 07, 2007 12:15 pm

Postby Mr-Slowly on Thu Mar 15, 2007 10:48 pm

*BUMB*
none comeone peeps
God Bless You
Mr-Slowly
Registered User
Registered User
 
Posts: 29
Joined: Wed Mar 07, 2007 12:15 pm


Return to PHP Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron