2013-10-07 38 views
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> 

目前,如果我從$query刪除cid ='$squadid'在calendar_start.php你可以看到所有數據庫中的事件,但網站上的每個成員也可以看到它們。

在我的表中的cid應該代表日曆ID IE。成員擁有日曆,但我無法弄清楚我錯在哪裏。

我希望我已經解釋了這不夠好,但如果你需要更多的只是讓我知道。

千恩萬謝

回答

0

在你calendar_start.php(也就是你的Ajax請求trigered文件)了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。 乾杯!

+0

嗨格魯吉亞,我已經嘗試過你的建議,但仍然不能得到它的工作不幸。我正確地把$ squadid = $ _POST ['squadid'];進入calendar_start.php? – dyer926

+0

第一AF一切,從阿賈克斯發送,那麼它; S正確的,你做了什麼 –

+0

當你的意思是通過Ajax發送你的意思是這條線:VAR瓦爾=「showmonth =」 + showmonth +「&showyear =」 + showyear +」 &squadid = <?= $ squadid;?>「;如果是的話,我已經添加了這個,但仍然不能看到事件。我是否缺少別的東西?當我進入這些小車轍的時候,它通常會顯得非常有趣。儘管如此,感謝您的幫助 – dyer926