0

我有一个有多个成员的网站,我希望每个成员都有自己的日历。我找到了一个教程来构建和事件日历女巫工作正常,但我无法尝试让事件显示在正确的日历上,要么每个人都可以看到数据库中的所有事件,要么没有人可以看到任何事件。

我的代码如下

calendar_start.php

<?php 

$showmonth = $_POST['showmonth'];
$showyear = $_POST['showyear'];
$showmonth = preg_replace('#[^0-9]#i', '', $showmonth);
$showyear = preg_replace('#[^0-9]#i', '', $showyear);


$day_count = cal_days_in_month(CAL_GREGORIAN, $showmonth, $showyear);
$pre_days = date('w', mktime(0,0,0, $showmonth, 1, $showyear));
$post_days = (6 - (date('w', mktime(0,0,0, $showmonth, $day_count, $showyear))));

echo '<div id="calender_wrap">';

echo '<div class="title_bar">';
echo '<div class="previouse_month"><input name="myBtn" type="submit" value="Previouse Month" onclick="javascript:last_month();"></div';
echo '<div class="show_month">' . $showmonth . '/' . $showyear . '</div>';
echo '<div class="next_month"><input name="myBtn" type="submit" value="Next Month" onclick="javascript:next_month();"></div>';
echo '</div>';

echo '<div class="week_days">';
echo '<div class="days_of_week">Sunday</div>';
echo '<div class="days_of_week">Monday</div>';
echo '<div class="days_of_week">Tuesday</div>';
echo '<div class="days_of_week">Wednesday</div>';
echo '<div class="days_of_week">Thursday</div>';
echo '<div class="days_of_week">Friday</div>';
echo '<div class="days_of_week">saturday</div>';
echo '<div class="clear"></div>';
echo '</div>';

/* Previouse Month filler Days */
if ($pre_days != 0) {
    for($i = 1; $i<=$pre_days; $i++) {
        echo '<div class="non_cal_day"></div>';
    }
}

/*Current Month filler Days */
include("scripts/connect_to_mysql.php");
for($i = 1; $i<= $day_count; $i++) {
    // get event logic

    $date = $i . '/' . $showmonth . '/' . $showyear;
    $query = "SELECT * FROM occurrences WHERE cid ='$squadid' AND start_date ='$date' ";
    $cal = mysqli_query($db_conx, $query);
    $num_rows = mysqli_num_rows($cal);
        if($num_rows > 0) {
            $event= '<a href="view_events.php"><h3 class="event_here">Events Here</h3></a>';
            }
        //end get event logic

    echo '<div class="cal_day">';
    echo '<div class="day_heading">' . $i . ' <a href="add_event.php"><div class="add_event"></div></a></div><br/>';
    if($num_rows != 0) { echo $event;}
    echo '</div>';
}

/* Next month filler days */
if ($post_days != 0) {
    for($i = 1; $i<=$post_days; $i++) {
        echo '<div class="non_cal_day"></div>';
    }
}

echo '</div>';

?>

show_calendar.php

<?php 
// Start_session, check if user is logged in or not, and connect to the database all in one included file
include_once("scripts/checkuserlog.php");
// Include the class files for auto making links out of full URLs and for Time Ago date formatting
include_once("wi_class_files/autoMakeLinks.php");
include_once ("wi_class_files/agoTimeFormat.php");
// Create the two new objects before we can use them below in this script
$activeLinkObject = new autoActiveLink;
$myObject = new convertToAgo;

// ------- ESTABLISH THE PAGE ID ACCORDING TO CONDITIONS ---------
$squadid = "";
if (isset($_GET['pid'])){ $squadid = $_GET['pid'];};
// ------- END ESTABLISH THE PAGE ID ACCORDING TO CONDITIONS ---------

//-------- GET EVENTS FROM TABLE-------------------------------------

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Calender</title>
<link href="style/calCss.css" rel="stylesheet" type="text/css" media="all" />
<link href="style/main.css" rel="stylesheet" type="text/css" />
<link rel="icon" href="logoicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="logoicon.ico" type="image/x-icon" />
<script language="javascript" type="text/javascript">
function initialCalendar() {
    var hr = new XMLHttpRequest();
    var url = "calender_start.php";
    var currentTime = new Date();
    var month = currentTime.getMonth() + 1;
    var year = currentTime.getFullYear();
    showmonth = month;
    showyear = year;
    var vars = "showmonth="+showmonth+"&showyear="+showyear;
    hr.open("POST", url, true);
    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    hr.onreadystatechange = function() {
        if(hr.readyState == 4 && hr.status == 200) {
            var return_data = hr.responseText;
            document.getElementById("showCalendar") .innerHTML = return_data;
        }
    }
    hr.send(vars);
    document.getElementById("showCalendar") .innerHTML = "processing...";
}
</script>
<script language="javascript" type="text/javascript">
function next_month() {
    var nextmonth = showmonth + 1;
    if(nextmonth > 12) {
        nextmonth = 1;
        showyear = showyear + 1;
    }
    showmonth = nextmonth;
    var hr = new XMLHttpRequest();
    var url = "calender_start.php";
    var vars = "showmonth="+showmonth+"&showyear="+showyear;
    hr.open("POST", url, true);
    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    hr.onreadystatechange = function() {
        if(hr.readyState == 4 && hr.status == 200) {
            var return_data = hr.responseText;
            document.getElementById("showCalendar").innerHTML = return_data;
        }
    }
    hr.send(vars);
    document.getElementById("showCalendar").innerHTML = "processing...";
}
</script>
<script language="JavaScript" type="text/javascript">
function last_month() {
    var lastmonth = showmonth - 1;
    if(lastmonth < 1) {
        lastmonth = 12;
        showyear = showyear - 1;
    }
    showmonth = lastmonth;
    var hr = new XMLHttpRequest();
    var url = "calender_start.php";
    var vars = "showmonth="+showmonth+"&showyear="+showyear;
    hr.open("POST", url, true);
    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    hr.onreadystatechange = function() {
        if(hr.readyState == 4 && hr.status == 200) {
            var return_data = hr.responseText;
            document.getElementById("showCalendar").innerHTML = return_data;
        }
    }
    hr.send(vars);
    document.getElementById("showCalendar").innerHTML = "processing...";
}
</script>
</head>

<body onload="initialCalendar();">
<?php include_once "header_template.php"; ?>
<table class="mainBodyTable" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="740" valign="top"><div><?php include_once "leaderBoardAd.php"; ?></div><br />
      <table width="90%" align="center" cellpadding="6">
        <tr>
          <td>
          <div id="showCalendar"></div>
          </td>
        </tr>
      </table></td>
    <td width="160" valign="top"><?php include_once "right_AD_template.php"; ?></td>
  </tr>
</table>
<?php include_once "footer_template.php"; ?>

</body>
</html>

目前,如果我cid ='$squadid'$querycalendar_start.php 中删除,您可以看到数据库中的所有事件,但网站上的每个成员也可以看到它们。

在我的表格中,cid应该代表日历 ID,即。成员有自己的日历,但我不知道哪里出错了。

我希望我已经很好地解释了这一点,但如果您需要更多,请告诉我。

非常感谢

4

1 回答 1

0

在您的 calendar_start.php(即由您的 ajax 请求触发的文件)中,var $squadid 为空。您需要将 $squadid 从 show_calendar.php 发送到 calendar_start.php 抛出您的 ajax 请求。

这是一个例子:

  //Ajax request example from show_calendar.php
    var hr = new XMLHttpRequest();
    var url = "calender_start.php";
    var currentTime = new Date();
    var month = currentTime.getMonth() + 1;
    var year = currentTime.getFullYear();
    showmonth = month;
    showyear = year;
    var vars = "showmonth="+showmonth+"&showyear="+showyear+"&squadid=<?= $squadid; ?>";
    hr.open("POST", url, true);
    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    hr.onreadystatechange = function() {
        if(hr.readyState == 4 && hr.status == 200) {
            var return_data = hr.responseText;
            document.getElementById("showCalendar") .innerHTML = return_data;
        }
    }
    hr.send(vars);
    document.getElementById("showCalendar") .innerHTML = "processing...";


    //Get the var in calendar_start.php add this line
    $squadid = $_POST['squadid'];

希望这可以帮助你m8。干杯!

于 2013-10-18T15:20:25.447 回答