2013-07-30 60 views
-2

这是我的日历的外观.. 我已经使用function.calender创建了日历,但现在我想禁用星期六和星期日列。我该怎么做?我想在我的日历功能中禁用星期六和星期日

在此先感谢。

我已经尝试了下面的代码。

function draw_calendar($month,$year){ 

     if($month=='1') 
     { 
      $strmonth='january'; 
     } 
     else if($month=='2') 
     { 
      $strmonth='february'; 
     } 
     else if($month=='3') 
     { 
      $strmonth='march'; 
     } 
     else if($month=='4') 
     { 
      $strmonth='april'; 
     } 
     else if($month=='5') 
     { 
      $strmonth='may'; 
     } 
     else if($month=='6') 
     { 
      $strmonth='june'; 
     } 
     else if($month=='7') 
     { 
      $strmonth='july'; 
     } 
     else if($month=='8') 
     { 
      $strmonth='august'; 
     } 
     else if($month=='9') 
     { 
      $strmonth='september'; 
     } 
     else if($month=='10') 
     { 
      $strmonth='october'; 
     } 
     else if($month=='11') 
     { 
      $strmonth='november'; 
     } 
     else if($month=='12') 
     { 
      $strmonth='december'; 
     } 




    /* draw table */ 
    $calendar = '<table cellpadding="0" cellspacing="0" class="calendar" align="center" ><tr><td align="center" colspan="7" style="border:1px solid gray;text-transform:uppercase;border-left:none;color:chocolate;height:30px;font-size:30px;padding:5px;"><b>'.$strmonth.' &nbsp; '.$year.'</b></td></tr>'; 

    /* table headings */ 
    $headings = array('<font color="red">Sunday</font>','Monday','Tuesday','Wednesday','Thursday','Friday','<font color="red">Saturday</font>'); 

    $calendar.= '<tr class="calendar-row"><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>'; 

    /* days and weeks vars now ... */ 
    $running_day = date('w',mktime(0,0,0,$month,1,$year)); 
    $days_in_month = date('t',mktime(0,0,0,$month,1,$year)); 
    $days_in_this_week = 1; 
    $day_counter = 0; 
    $dates_array = array(); 


    /* if(($headings[0])) 
     { 
      $sday='style="color:red"'; 
     } 
     else 
     { 
      $sday='style="color:gray"'; 
     } 
    */ 


    /* row for week one */ 

    $calendar.= '<tr class="calendar-row" >'; 


    /* print "blank" days until the first of the current week */ 
    for($x = 0; $x < $running_day; $x++): 
     $calendar.= '<td class="calendar-day-np" > </td>'; 
     $days_in_this_week++; 
    endfor; 

    /* keep going with days.... */ 

    for($list_day = 1; $list_day <= $days_in_month; $list_day++): 

    if(isset($_SESSION['client']) && !empty($_SESSION['client'])) 
    { 

     $s="select * from tbl_job_schedule where jobdate='".$strmonth."-".$list_day."-".$_SESSION['yy']."' and clientname='".$_SESSION['client']."'"; 

     $q=mysql_query($s) or die($s); 
     $rw=mysql_fetch_array($q); 
    } 
    else if(isset($_SESSION['user']) && !empty($_SESSION['user'])) 
    { 
     $s="select * from tbl_job_schedule where jobdate='".$strmonth."-".$list_day."-".$_SESSION['yy']."' and username='".$_SESSION['user']."'"; 

     $q=mysql_query($s) or die($s); 
     $rw=mysql_fetch_array($q); 
    } 


     if($rw['status']=='schedule') 
     { 
      $strimg='<img src="images/schedule.png" height="35" width="35"/>'; 
     } 
     else if($rw['status']=='schwork') 
     { 
      $strimg='<img src="images/schedule.png" height="35" width="35"/>&nbsp;<img src="images/work.png" height="35" width="35"/>'; 
     } 
     else if($rw['status']=='schworkcmnt' && $rw['client_cmnt']=='') 
     { 
      $strimg='<img src="images/schedule.png" height="35" width="35"/>&nbsp;<img src="images/work.png"height="35" width="35" />'; 
     } 
     else if($rw['status']=='schworkcmnt' && $rw['client_cmnt']!='') 
     { 
      $strimg='<img src="images/schedule.png" height="35" width="35"/>&nbsp;<img src="images/work.png" height="35" width="35"/><br><img src="images/cmnt.png" height="35" width="35"/>'; 
     } 
     else 
     { 
      $strimg=''; 
     } 

     $calendar.= '<td class="calendar-day" onClick="OpenWin('.$list_day.');" >'; 

      $calendar.= '<div class="day-number" >'.$list_day.'</div><div style="height:90px;width:80px;border:0px solid yellow;float:right;padding-right:0px;padding-top:10px;" >'.$strimg.'</div><div style="height:40px;width:150px;padding:0px;border:0px solid yellow;float:left;margin-top:50px;margin-right:20px;font-size:14px;color:gray;text-transform:capitalize;" ><b>'.$rw['client_comp'].'</b></div>'; 

      /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !! IF MATCHES FOUND, PRINT THEM !! **/ 
      $calendar.= str_repeat('<p> </p>',2); 

     $calendar.= '</td>'; 
     if($running_day == 6): 
      $calendar.= '</tr>'; 
      if(($day_counter+1) != $days_in_month): 
       $calendar.= '<tr class="calendar-row">'; 
      endif; 
      $running_day = -1; 
      $days_in_this_week = 0; 
     endif; 
     $days_in_this_week++; $running_day++; $day_counter++; 
    endfor; 

    /* finish the rest of the days in the week */ 
    if($days_in_this_week < 8): 
     for($x = 1; $x <= (8 - $days_in_this_week); $x++): 
      $calendar.= '<td class="calendar-day-np"> </td>'; 
     endfor; 
    endif; 

    /* final row */ 
    $calendar.= '</tr>'; 

    /* end the table */ 
    $calendar.= '</table>'; 

    /* all done, return result */ 
    return $calendar; 


} 

/* sample usages */ 


?> 
+0

建议:而不是所有'if($ month =='1').. else..else..'你可以使用'$ strmonth = strtolower(date(“F”,mktime(0,0, 0,$ month,1)));' – bansi

回答

0

试试这个:

//all other code. Check if date of the week equals 0-sunday or 6-saturday 
if($running_day==0 || $running_day==6) { 
$calendar.= '<td>&nbsp;</td>'; 
} 
else 
{ 
$calendar.= '<td class="calendar-day" onClick="OpenWin('.$list_day.');" >'; 
//... all other code 
$calendar.= '</td>'; 
} 

注:代码没有测试。

+0

是的......它的作品现在感谢budy :-) –

相关问题