Open igrrik opened 10 years ago
You can add the request params:
$start = $_REQUEST['from'] / 1000;
$end = $_REQUEST['to'] / 1000;
That's the $start and $end that the calendar gives to your script ;)
PS: The error 500 is a php error, so, the script is bad. If you run directly, maybe it shows a warning / fatal error
The code must somewhere break. If you give us a more complete source code we can investigate.
This is how i implemented my own PHP code
// Will get me all the appointments
$this->_appointmentList = $this->AppointmentRepository->retrieveList(null,null,null,null);
private final function createFileContents() {
$string = "{";
$string .= '"success": 1, ';
$string .= '"result": [';
foreach ($this->_appointmentList as $appointment ) {
$this->_appointmentId = $appointment->getAppointmentId();
$this->_packageRecord = $appointment->getPackageRecord();
$this->_packageName = $this->_packageRecord->getName();
$this->_appointeeName = $appointment->getUserRecord()->getDisplayName();
$this->_trainneeName = $appointment->getTrainerRecord()->getDisplayName();
$string .= '{';
$string .= $this->getId();
$string .= $this->getMonthTitle();
$string .= $this->getTitle($appointment);
$string .= '"url":"appointment-info.php?appointment='.$this->_appointmentId.'",';
$string .= '"class":"event-info",';
$startDate = $this->findStartDate($appointment->getStartTime());
$string .= '"start":"'.$startDate.'",';
$endDate = $this->calculateEndDate($appointment->getStartTime(), $appointment->getDuration());
$string .= '"end":"'.$endDate.'",';
$string .= '"color": "#'.$this->_packageRecord->getColor().'"';
$string .= '},';
}
$string = substr($string, 0, -1);
$string .= "]";
$string .= "}";
file_put_contents($this->_fileLocation, $string);
}
Now that i am looking at it, it might not be the easiest to understand. I'll see about creating a simple helper class in order for people to use that class in order to retrieve data from the database and parsing them into the file.
I think that the example is easy to understand...
But, maybe add some link to Wiki examples, or similar, will be great
private final function createFileContents() {
$this->_appointmentList = $this->AppointmentRepository->retrieveList(null,null,null,null);
$events = array();
foreach ($this->_appointmentList as $appointment ) {
$this->_appointmentId = $appointment->getAppointmentId();
$this->_packageRecord = $appointment->getPackageRecord();
$this->_packageName = $this->_packageRecord->getName();
$this->_appointeeName = $appointment->getUserRecord()->getDisplayName();
$this->_trainneeName = $appointment->getTrainerRecord()->getDisplayName();
$event = array();
$event['id'] = $this->getId();
$event['monthtitle'] = $this->getMonthTitle();
$event['title'] . $this->getTitle($appointment);
$event['url'] = 'appointment-info.php?appointment='.$this->_appointmentId;
$event['class'] = "event-info";
$event['start'] = $this->findStartDate($appointment->getStartTime());
$event['end'] = $this->calculateEndDate($appointment->getStartTime(), $appointment->getDuration());
$event['color'] = "#".$this->_packageRecord->getColor();
$events[] = $event;
}
file_put_contents($this->_fileLocation, json_encode(array('success' => 1, 'result' => $events)));
}
Maybe something like this. Less code.
I am using the script that you provided as an example and it doesn't work.
<?php
$db = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'username', 'password');
$start = $_REQUEST['from'] / 1000;
$end = $_REQUEST['to'] / 1000;
$sql = sprintf('SELECT * FROM events WHERE `datetime` BETWEEN %s and %s',
$db->quote(date('Y-m-d', $start)), $db->quote(date('Y-m-d', $end)));
$out = array();
foreach($db->query($sql) as $row) {
$out[] = array(
'id' => $row->id,
'title' => $row->name,
'url' => Helper::url($row->id),
'start' => strtotime($row->datetime) . '000',
'end' => strtotime($row->datetime_end) .'000'
);
}
echo json_encode(array('success' => 1, 'result' => $out));
exit;
?>
What happen if you executes only these file?
Has you a Helper class, with url method? Helper is not an php standard class. you need to remove it...
And, whats your table structure for events? Has datetime with DATE, DATETIME, o TIMESTAMP?
My table structure is: id - int name - varchar url - varchar datetime - DATETIME datetime_end - DATETIME
When I open page with calendar, I have this error So as you can see, $start and $end params have their value.
I've executed this query SELECT * FROM events WHERE datetime
BETWEEN %s and %s' in phpmyadmin, and it's working.
I've tried to execute this script, and everything is also working.
<?php
$start = 1409565600;
$end = 1412090956;
$strSQL = "SELECT * FROM events WHERE `datetime` BETWEEN '".date('Y-m-d', $start)."' and '".date('Y-m-d', $end)."'";
$query = mysql_query($strSQL);
while($row = mysql_fetch_array($query)) {
echo "<h1>".strtotime($row['datetime']).'000'."</h1>";
}
?>
But when I'm executing the example-script, I get an error.
In inspector, chec network tab and see what is returned by XHR. YOu can see JSON object there. May be something not correct in output.
And with these?
<?php
$start = 1409565600;
$end = 1412090956;
$strSQL = "SELECT * FROM events WHERE `datetime` BETWEEN '".date('Y-m-d', $start)."' and '".date('Y-m-d', $end)."'";
$query = mysql_query($strSQL);
while($row = mysql_fetch_array($query)) {
$out[] = array(
'id' => $row['id'],
'title' => $row['name'],
'url' => $row['url'],
'start' => strtotime($row['datetime']) . '000',
'end' => strtotime($row['datetime_end']) .'000'
);
}
echo json_encode(array('success' => 1, 'result' => $out));
exit;
?>
If doesn't work, please, try to execute it directly (the php script), and see what ever it prints...
Eleazan, yes. I've tried this one before and it's working
Serhioromano, I am sorry, I can't find XHRt in Chrome-inspector-network tab. But, it says that there are 2 anonymous function
1 - is in calendar.js : 897 2 - in my page, on the line where I initialize the calendar
<script type="text/javascript">
var calendar = $("#calendar").calendar( //this line
{
tmpl_path: "bootstrap-calendar-master/tmpls/",
events_source: 'calTest.php',
onAfterViewLoad: function(view) {
$("#monthHeader").text(this.getTitle());
}
});
</script>
The internal server error is saying you that you have a php error.
If you open that calTest.php?from=141210720000000&to1412................ (dbl click i believe), it can show the error. Have you tested?
Eleazan, yes, I have tested it.
So, maybe you has the errors deactivated?
Set these sentences
error_reporting(E_ALL);
ini_set("display_errors", 1);
At the beginning of calTest
I've done it, but nothing happens. Do I need to write anything else?
I can upload all my files and database to hosting, and give you access to it. Maybe it can help?
It's not usual do that...
But, you have my mail in my profile, if i have some time (now i have 1h to lunch, but then, maybe i have time), i can check it...
I not promise nothing.
Well it's just an offer. It's not a hurry, so if you have time in 2-3 weeks, I'll be thankful to you.
I am downloading all the events for right now, and while it works I am okay.
If you have a blank screen then you might want to check PHP error log.
I am trying to use your php script and it doesn't work. I am always having this problem
A table in a database is okay. The comparison is also working, I've checked it in phpmyadmin.
Also everything work if use this script
$sql = "SELECT * FROM Calendar";
$out = array(); foreach($db->query($sql) as $row) { $out[] = array( 'id' => $row['id'], 'title' => $row['name'], 'class' => "event-warning", 'url' => $row['url'], 'start' => strtotime($row['datetime']). '000', 'end' => strtotime($row['datetime_end']).'000' ); }
But I want to know how to load events using $start and $end