Serhioromano / bootstrap-calendar

Full view calendar with year, month, week and day views based on templates with Twitter Bootstrap.
http://bootstrap-calendar.eivissapp.com/
MIT License
3.02k stars 1.29k forks source link

Some problems with php script #420

Open igrrik opened 10 years ago

igrrik commented 10 years ago

I am trying to use your php script and it doesn't work. I am always having this problem 2014-09-30 20 15 45 2014-09-30 20 19 42

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

eleazan commented 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

steliosph commented 10 years ago

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.

eleazan commented 10 years ago

I think that the example is easy to understand...

But, maybe add some link to Wiki examples, or similar, will be great

Serhioromano commented 10 years ago
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.

igrrik commented 10 years ago

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;
    ?>
eleazan commented 10 years ago

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?

igrrik commented 10 years ago

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 2014-10-01 20 24 39 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.

Serhioromano commented 10 years ago

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.

eleazan commented 10 years ago

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...

igrrik commented 10 years ago

Eleazan, yes. I've tried this one before and it's working 2014-10-02 15 11 40

igrrik commented 10 years ago

Serhioromano, I am sorry, I can't find XHRt in Chrome-inspector-network tab. But, it says that there are 2 anonymous function 2014-10-02 15 24 14

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>
eleazan commented 10 years ago

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?

igrrik commented 10 years ago

Eleazan, yes, I have tested it. 2014-10-02 15 35 54

eleazan commented 10 years ago

So, maybe you has the errors deactivated?

Set these sentences

error_reporting(E_ALL);
ini_set("display_errors", 1);

At the beginning of calTest

igrrik commented 10 years ago

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?

eleazan commented 10 years ago

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.

igrrik commented 10 years ago

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.

Serhioromano commented 10 years ago

If you have a blank screen then you might want to check PHP error log.