2010-04-20 2 views
0

Je crée un calendrier.Insérer une date, calculer une fonction, dans un calendrier

je remplir l'année et la date comme celui-ci
< < < < < Année >>>>>>
< < < < < mois >>>>>>

En cliquant sur les flèches l'année et le mois augmentent et diminuent.

Maintenant, je dois remplir les dates pour l'année et le mois choisis.

Je calcule le premier jour du mois et la dernière date du mois.

Les dates doivent commencer à remplir dès le premier jour.

Si le premier jour est jeudi la date 1 doit être le jeudi et les prochains jours doit suivre que jusqu'à la dernière date.

Ce sont mes fonctions dans mon contrôleur

function phpcal() 
    { 
     $month=04; 
     $day=01; 
     $year=2010; 
     echo date("D", mktime(0,0,0,$month,$day,$year)); //here i am calculating the first day of the month 
     echo '<br>lastdate'.date("t", strtotime($year . "-" . $month . "-01"));'' here i am calculating the lasdt date of the month 
     //echo '<br>'.$date_end = $this->lastOfMonth(); 
     $this->load->view('phpcal'); 
    } 
function firstOfMonth($m1,$y1) 
{ 
      return date("m/d/Y", strtotime($m1.'/01/'.$y1.' 00:00:00')); 
} 
function lastOfMonth() 
{ 
      return date("m/d/Y", strtotime('-1 second',strtotime('+1                month',strtotime(date('m').'/01/'.date('Y').' 00:00:00')))); 
} 
function phpcalview() 
    { 
     $year = $this->input->post('yearvv'); 
     $data['year'] = $this->adminmodel->selectyear(); 
     $data['date'] = $this->adminmodel->selectmonth(); 
     //print_r($data['date']); 

     $this->load->view('phpcal',$data); 
    } 

Ceci est ma page vue

<table cellpadding="2" cellspacing="0" border="1" bgcolor="#CCFFCC" align="center" class="table_Style_Border"> 
<? if(isset($date)) 
{ 
foreach($date as $row) 
{?> 


<tr> 
    <td><?= $row['dbDate1'];?></td> <td><?= $row['dbDate2'];?></td> <td><?= $row['dbDate3'];?></td> <td><?= $row['dbDate4'];?></td>  <td><?= $row['dbDate5'];?></td> <td><?= $row['dbDate6'];?></td> <td><?= $row['dbDate7'];?></td> 
</tr> 
<tr bgcolor="#FFFFFF"> 
    <td><?= $row['dbDate8'];?></td> <td><?= $row['dbDate9'];?></td> <td><?= $row['dbDate10'];?></td> <td><?= $row['dbDate11'];?></td> <td><?= $row['dbDate12'];?></td> <td><?= $row['dbDate13'];?></td> <td><?= $row['dbDate14'];?></td> 
</tr> 
<tr> 
    <td><?= $row['dbDate15'];?></td> <td><?= $row['dbDate16'];?></td> <td><?= $row['dbDate17'];?></td> <td><?= $row['dbDate18'];?></td> <td><?= $row['dbDate19'];?></td> <td><?= $row['dbDate20'];?></td> <td><?= $row['dbDate21'];?></td> 
</tr> 
<tr bgcolor="#FFFFFF"> 
    <td><?= $row['dbDate22'];?></td> <td><?= $row['dbDate23'];?></td> <td><?= $row['dbDate24'];?></td> <td><?= $row['dbDate25'];?></td> <td><?= $row['dbDate26'];?></td> <td><?= $row['dbDate27'];?></td> <td><?= $row['dbDate28'];?></td> 
</tr> 
<tr> 
    <td><?= $row['dbDate29'];?></td> <td><?= $row['dbDate30'];?></td> <td><?= $row['dbDate31'];?></td> <td><?= $row['dbDate1'];?></td> <td><?= $row['dbDate1'];?></td> <td><?= $row['dbDate1'];?></td> <td><?= $row['dbDate1'];?></td> 
</tr> 

</tr> 
<? }} ?> 
</table> 

Comment puis-je insérer les dates à partir du jour calculé dans la fonction phpcal?

Répondre

1

Ceci est un script de calendrier que j'ai partiellement écrit. Il peut vérifier les données de la base de données par rapport à une journée et créer un lien. Jetez un coup d'oeil, peut-être il est utile:

// Start table 
$display .= '<table class="calendar_table" border="0">'; 
// set the default timezone to use. Available since PHP 5.1 
date_default_timezone_set('UTC'); 
//This gets today's date 
$date = time(); 
// Set the value to today 
$today = date('d', $date); 
//This will get the value from the url 
if($_GET['month'] && $_GET['year']){ 
    $month = $_GET['month']; 
    $year = $_GET['year']; 
}else{ 
    //This puts the day, month, and year in seperate variables 
    $day = date('d', $date); 
    $month = date('m', $date); 
    $year = date('Y', $date); 
} 
// Set values for previous and next month 
$nextMonth = $month+1; 
$previousMonth = $month-1; 
// And for the year 
$nextYear = $year; 
$previousYear = $year; 

// Check the month (there are only 12 so, fix) 
if($month == '1'){ 
    $previousMonth = '12'; 
    $previousYear = $previousYear-1; 
}elseif($month == '12'){ 
    $nextMonth = '1'; 
    $nextYear = $nextYear+1; 
} 

//Here we generate the first day of the month 
$first_day = mktime(0,0,0,$month, 1, $year); 

//This gets us the month name 
$title = date('F', $first_day); 

//Here we find out what day of the week the first day of the month falls on 
$day_of_week = date('D', $first_day); 

//Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero 
switch($day_of_week){ 
    case "Sun": $blank = 0; break; 
    case "Mon": $blank = 1; break; 
    case "Tue": $blank = 2; break; 
    case "Wed": $blank = 3; break; 
    case "Thu": $blank = 4; break; 
    case "Fri": $blank = 5; break; 
    case "Sat": $blank = 6; break; 
} 

//We then determine how many days are in the current month 
$days_in_month = cal_days_in_month(0, $month, $year); 

// Get the url, check for home or module 
if($_GET['pageName'] == 'Home'){ 
    $link_prefix = '?pageName=Home'; 
}else{ 
    $link_prefix = '?module=Agenda'; 
} 

//Here we start building the table heads 
$display .= "<tr class='calendar_header'><td class='calendar_navigation'><a href='".$link_prefix.'&month='.$previousMonth."&year=".$previousYear."' class=navigationLink>&lt;&lt;</a></td><td colspan='5' class='calendar_title_frontpage'> $title $year </td><td class='calendar_navigation'><a href='".$link_prefix.'&month='.$nextMonth."&year=".$nextYear."' class=navigationLink>&gt;&gt;</a></td></tr>"; 
$display .= "<tr class='calendar_weeks'><td class='calendar_weeks'>Zo</td><td class='calendar_weeks'>Ma</td><td class='calendar_weeks'>Di</td><td class='calendar_weeks'>Wo</td><td class='calendar_weeks'>Do</td><td class='calendar_weeks'>Vr</td><td class='calendar_weeks'>Za</td></tr>"; 

//This counts the days in the week, up to 7 
$day_count = 1; 

$display .= "<tr>"; 
//first we take care of those blank days 
while ($blank > 0){ 
    $display .= "<td class='calendar_days'>&nbsp;</td>"; 
    $blank = $blank-1; 
    $day_count++; 
} 

//sets the first day of the month to 1 
$day_num = 1; 

// Create query to get all the info from the database 
$BlaatCms->DB->build(array('select' => 'id,dates,title,description','from' => 'calendar')); 


// Create array 
$events = array(); 

// Getting the data from the database and put it in an array 
while($calendar = $BlaatCms->DB->fetch($BlaatCms->DB->execute())){ 
    if(date('m', $calendar['dates']) == $month){ 
     $events[intval($BlaatCms->unixstamp_to_mmddyyyy($calendar['dates']))] .= '<a href="?module=Agenda&id='.$calendar['id'].'">'.date('d',$calendar['dates']).'</a>'; 
    } 
} 


//count up the days, untill we've done all of them in the month 
while ($day_num <= $days_in_month){ 

    if(array_key_exists($day_num,$events)){ 
     if($day_num == $today && $month == date('m', $date) && $year == date('Y', $date)){ 
      $display .= "<td class='calendar_days_event_current'>".$events[$day_num]."</td>"; 
     }else{ 
      $display .= "<td class='calendar_days_event'>".$events[$day_num]."</td>"; 
     } 

    }else{ 
     if($day_num == $today && $month == date('m', $date) && $year == date('Y', $date)){ 
      $display .= "<td class='calendar_days_current'>".$day_num."</td>"; 
     }else{ 
      $display .= "<td class='calendar_days'>".$day_num."</td>"; 
     } 
    } 

    $day_num++; 
    $day_count++; 

    //Make sure we start a new row every week 
    if ($day_count > 7){ 
     $display .= "</tr><tr align=center>"; 
     $day_count = 1; 
    } 

} 

//Finaly we finish out the table with some blank details if needed 
while ($day_count >1 && $day_count <=7){ 
    $display .= "<td class='calendar_days'>&nbsp;</td>"; 
    $day_count++; 
} 

$display .= "</tr>"; 

// Show link to nieuws archive 
$display .= '<tr><td colspan="7" class="calendar_readmore_frontpage"><a href="?module=Agenda">'.$agenda_config['textOverview'].'</a></td>'; 

$display .= "</table>"; 
// Echo the table 
echo $display; 
Questions connexes