有 Zend 或 jQuery 库可以为我完成这个基本的日历功能吗?

发布于 2024-09-10 02:35:25 字数 6688 浏览 2 评论 0原文

我有一个日历应用程序,在该日历应用程序中,有一个日历的“迷你视图”。那个小部件只显示当前选择的月份的天数,当您单击数字时,它会打开一个新页面并将 GET 数据发送到该新页面(以显示 MySQL 信息等)。

重点是:这个小迷你日历不根本没有做太多事情,我正在努力将其变成 Zend Framework MVC 中的一部分。我们也有 jQuery。我想知道是否有任何内置代码可以轻松地完成我们尝试使用自己的代码执行的操作。

我们的代码(按程序完成):

<?php
    /***
      This script file is the left panel calendar (small)
    */

    //Required variables initializion starts (important in the case of create new event, to avoid PHP notices).

    $day    =    "";
    $month    =    "";
    $year    =    "";
    $sel    =    "";
    $what    =    "";
    $page    =    "index.php";
    $param    =    "";
    $index    =    "";
    $functionLast    =    "goLastMonth";
    $functionNext    =    "goNextMonth";
    $sendFunction    =    "sendToForm";

    if(isset($_GET['index'])) //if index page
    {
        $index    =    $_GET['index'];
    }
    if(isset($_GET['type'])) //if sype is set
    {
      $param    =    "&amp;type=".$_GET['type'];
    }
    if(isset($_GET['page'])) //if page is set
    {
        $page            =    "calendar.php";
        $param            =    '&amp;page=calendar';
        $functionLast    =    "getLastMonth";
        $functionNext    =    "getNextMonth";
        $sendFunction    =    "sendToTextBox";
    }

    if(!isset($calWidth) && !isset($calHeight)) //cal width /height check
    {
        $calWidth    =    CALENDAR_WIDTH;
        $calHeight    =    CALENDAR_HEIGHT;
    }

    if(isset($_GET["day"])) //if day is set
        $day = $_GET["day"]; //get it

    if(isset($_GET["month"])) //if month is set
        $month = $_GET["month"]; //..

    if(isset($_GET["year"])) //..
        $year = $_GET["year"]; //

    if(isset($_GET["sel"]))
        $sel = $_GET["sel"];

    if(isset($_GET["what"]))
        $what = $_GET["what"];

    if(isset($_GET['date']))
    {
        $date    =    $_GET['date'];
        list($year,$month,$day) = explode("-",$date); //split date into pieces
    }

    if($day == "") $day = date("j");  //if day is blank, get today

    if($month == "") $month = date("m");  //if month is blank, get this month

    if($year == "") $year = date("Y"); //if year is blank, get this year
    //echo $day."-".$month."-".$year;die;
    //echo '<br>';
    if(!checkdate($month, $day, $year)) { //if not a valida date
      if(isset($_GET["month"]))  { //try to get number of days for this month as this seems the last day of the month. for example if today is 31 of August and you are calling ?month=9&year=2009 it gives you wrong results
        $day = date("t", strtotime($year . "-" . $month . "-01")); //so give you 30.
      }
    }

    $printabledate  = $year."-".$month."-".$day;

    $currentTimeStamp = strtotime("$year-$month-$day");
    $monthName = date("F", $currentTimeStamp);
    $numDays = date("t", $currentTimeStamp);
    $counter = 0;
?>

<br />
<div id="loading1" class="a_loading1">
    <iframe src="<?php echo SITE_URL?>/loading-msg.php" scrolling="no" frameborder="0"  class="markup a_position"></iframe>
</div>

<table  class="mini-cal-table">
    <tr class="tprowbgcolor">
        <td class="arrow" colspan='1' align="center"><input type='button' class='buttonleft' onclick='<?php echo "$functionLast($month,$year,\"$page\",\"$index\")"; ?>' onmousedown="this.className='maincalbutton_active_left'" onmouseout="this.className='buttonleft'" /></td>
        <td class="title" colspan='5'><span class='title'><?php echo $monthName . " " . $year; ?></span></td>
        <td class="arrow" colspan='1' align="center"><input type='button' class='buttonright' onclick='<?php echo "$functionNext($month,$year,\"$page\",\"$index\")"; ?>' onmousedown="this.className='maincalbutton_active_right'" onmouseout="this.className='buttonright'" /></td>
    </tr>
    <tr>
        <td class='wd-titles'>Su</td>
        <td class='wd-titles'>Mo</td>
        <td class='wd-titles'>Tu</td>
        <td class='wd-titles'>We</td>
        <td class='wd-titles'>Th</td>
        <td class='wd-titles'>Fr</td>
        <td class='wd-titles'>Sa</td>
    </tr>
    <tr>
<?php
    for($i = 1; $i < $numDays+1; $i++, $counter++)
    {
        $timeStamp = strtotime("$year-$month-$i");
        if($i == 1)
        {
        // Workout when the first day of the month is
        $firstDay = date("w", $timeStamp);

        for($j = 0; $j < $firstDay; $j++, $counter++)
        echo "<td>&nbsp;</td>";
        }

        if($counter % 7 == 0) {
          echo "</tr><tr>";
        }

        if(date("w", $timeStamp) == 0) {
          //$class = "class='weekend'";
          $tdclass = "weekend";
        } else {
          if($i == date("d") && $month == date("m") && $year == date("Y")) {
            //$class = "class='today'";
            $tdclass = "today";
          }
          else {
            //$class = "class='normal'";
            $tdclass = "normal";
          }
        }
        $zero = "";
        if($i < 10 )
        {
            $zero = "0";
        }
        $month = round($month);
        if($month < 10)
        {
            $month = "0".$month;
        }
        $date  = $year."-".$month."-".$zero.$i;
?>

<td class="<?php echo $tdclass?>"><?php
    if(!isset($_GET['page']))    {
    ?><a href='<?php echo SITE_URL; ?>/agenda.php?date=<?php echo $year; ?>-<?php echo $month; ?>-<?php echo $zero.$i; ?>'><?php echo $i?></a>

<?php }    else    {
?>

<a onclick='<?php echo "$sendFunction($i,\"$date\",$numDays,\"$index\",\"$type\")"; ?>'><?php echo $i?></a>

<?php

}
?></td>

<?php
    }
?>
    </tr>
</table>
<script language="javascript" type="text/javascript">
    //<![CDATA[
    function goLastMonth(month,year,page,index) {
    // If the month is January, decrement the year.
      if(month == 1) {
        --year;
        month = 13;
      }

      var url =

      document.location.href = page+"?month="+(month-1)+"&year="+year+"<?php echo $param?>";
    }

    function goNextMonth(month,year,page,index)
    {
        // If the month is December, increment the year.
        if(month == 12)
        {
            ++year;
            month = 0;
        }
        document.location.href = page+"?month="+(month+1)+"&year="+year+"<?php echo $param?>";
    }
    //]]>
</script>

I have a calendar application, and in that calendar application, there is a "mini view" of a calendar. That little widget only displays the days of the currently chosen month and when you click the number it opens a new page and sends GET data to that new page (to display MySQL info, etc.)

The point is: this little mini-calendar doesn't do much at all, and I'm working to turn it into a partial in Zend Framework MVC. We have jQuery as well. I'm wondering if there is any built-in code that will easily do what we are trying to do with our own code.

Our code (done procedurally):

<?php
    /***
      This script file is the left panel calendar (small)
    */

    //Required variables initializion starts (important in the case of create new event, to avoid PHP notices).

    $day    =    "";
    $month    =    "";
    $year    =    "";
    $sel    =    "";
    $what    =    "";
    $page    =    "index.php";
    $param    =    "";
    $index    =    "";
    $functionLast    =    "goLastMonth";
    $functionNext    =    "goNextMonth";
    $sendFunction    =    "sendToForm";

    if(isset($_GET['index'])) //if index page
    {
        $index    =    $_GET['index'];
    }
    if(isset($_GET['type'])) //if sype is set
    {
      $param    =    "&type=".$_GET['type'];
    }
    if(isset($_GET['page'])) //if page is set
    {
        $page            =    "calendar.php";
        $param            =    '&page=calendar';
        $functionLast    =    "getLastMonth";
        $functionNext    =    "getNextMonth";
        $sendFunction    =    "sendToTextBox";
    }

    if(!isset($calWidth) && !isset($calHeight)) //cal width /height check
    {
        $calWidth    =    CALENDAR_WIDTH;
        $calHeight    =    CALENDAR_HEIGHT;
    }

    if(isset($_GET["day"])) //if day is set
        $day = $_GET["day"]; //get it

    if(isset($_GET["month"])) //if month is set
        $month = $_GET["month"]; //..

    if(isset($_GET["year"])) //..
        $year = $_GET["year"]; //

    if(isset($_GET["sel"]))
        $sel = $_GET["sel"];

    if(isset($_GET["what"]))
        $what = $_GET["what"];

    if(isset($_GET['date']))
    {
        $date    =    $_GET['date'];
        list($year,$month,$day) = explode("-",$date); //split date into pieces
    }

    if($day == "") $day = date("j");  //if day is blank, get today

    if($month == "") $month = date("m");  //if month is blank, get this month

    if($year == "") $year = date("Y"); //if year is blank, get this year
    //echo $day."-".$month."-".$year;die;
    //echo '<br>';
    if(!checkdate($month, $day, $year)) { //if not a valida date
      if(isset($_GET["month"]))  { //try to get number of days for this month as this seems the last day of the month. for example if today is 31 of August and you are calling ?month=9&year=2009 it gives you wrong results
        $day = date("t", strtotime($year . "-" . $month . "-01")); //so give you 30.
      }
    }

    $printabledate  = $year."-".$month."-".$day;

    $currentTimeStamp = strtotime("$year-$month-$day");
    $monthName = date("F", $currentTimeStamp);
    $numDays = date("t", $currentTimeStamp);
    $counter = 0;
?>

<br />
<div id="loading1" class="a_loading1">
    <iframe src="<?php echo SITE_URL?>/loading-msg.php" scrolling="no" frameborder="0"  class="markup a_position"></iframe>
</div>

<table  class="mini-cal-table">
    <tr class="tprowbgcolor">
        <td class="arrow" colspan='1' align="center"><input type='button' class='buttonleft' onclick='<?php echo "$functionLast($month,$year,\"$page\",\"$index\")"; ?>' onmousedown="this.className='maincalbutton_active_left'" onmouseout="this.className='buttonleft'" /></td>
        <td class="title" colspan='5'><span class='title'><?php echo $monthName . " " . $year; ?></span></td>
        <td class="arrow" colspan='1' align="center"><input type='button' class='buttonright' onclick='<?php echo "$functionNext($month,$year,\"$page\",\"$index\")"; ?>' onmousedown="this.className='maincalbutton_active_right'" onmouseout="this.className='buttonright'" /></td>
    </tr>
    <tr>
        <td class='wd-titles'>Su</td>
        <td class='wd-titles'>Mo</td>
        <td class='wd-titles'>Tu</td>
        <td class='wd-titles'>We</td>
        <td class='wd-titles'>Th</td>
        <td class='wd-titles'>Fr</td>
        <td class='wd-titles'>Sa</td>
    </tr>
    <tr>
<?php
    for($i = 1; $i < $numDays+1; $i++, $counter++)
    {
        $timeStamp = strtotime("$year-$month-$i");
        if($i == 1)
        {
        // Workout when the first day of the month is
        $firstDay = date("w", $timeStamp);

        for($j = 0; $j < $firstDay; $j++, $counter++)
        echo "<td> </td>";
        }

        if($counter % 7 == 0) {
          echo "</tr><tr>";
        }

        if(date("w", $timeStamp) == 0) {
          //$class = "class='weekend'";
          $tdclass = "weekend";
        } else {
          if($i == date("d") && $month == date("m") && $year == date("Y")) {
            //$class = "class='today'";
            $tdclass = "today";
          }
          else {
            //$class = "class='normal'";
            $tdclass = "normal";
          }
        }
        $zero = "";
        if($i < 10 )
        {
            $zero = "0";
        }
        $month = round($month);
        if($month < 10)
        {
            $month = "0".$month;
        }
        $date  = $year."-".$month."-".$zero.$i;
?>

<td class="<?php echo $tdclass?>"><?php
    if(!isset($_GET['page']))    {
    ?><a href='<?php echo SITE_URL; ?>/agenda.php?date=<?php echo $year; ?>-<?php echo $month; ?>-<?php echo $zero.$i; ?>'><?php echo $i?></a>

<?php }    else    {
?>

<a onclick='<?php echo "$sendFunction($i,\"$date\",$numDays,\"$index\",\"$type\")"; ?>'><?php echo $i?></a>

<?php

}
?></td>

<?php
    }
?>
    </tr>
</table>
<script language="javascript" type="text/javascript">
    //<![CDATA[
    function goLastMonth(month,year,page,index) {
    // If the month is January, decrement the year.
      if(month == 1) {
        --year;
        month = 13;
      }

      var url =

      document.location.href = page+"?month="+(month-1)+"&year="+year+"<?php echo $param?>";
    }

    function goNextMonth(month,year,page,index)
    {
        // If the month is December, increment the year.
        if(month == 12)
        {
            ++year;
            month = 0;
        }
        document.location.href = page+"?month="+(month+1)+"&year="+year+"<?php echo $param?>";
    }
    //]]>
</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼中杀气 2024-09-17 02:35:25

jQuery 有许多不错的日历选项,以下是 UI 核心的一部分:

http://jqueryui.com/演示/日期选择器/

jQuery has many good calendar options, the following being a part of the UI core:

http://jqueryui.com/demos/datepicker/

忘羡 2024-09-17 02:35:25

Zendx 还支持 jqueryui 日期选择器。 示例

Also Zendx supports the jqueryui datepicker. Example

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文