I am trying to use the Scheduler with PHP wrappers, the data returns in a way that LOOKS like it should work...but doesn't for some reason. Here is how it works:
The initial page loads:
After, as you can see, the first call to the listener is made. I am not posting the code to the listener, as it just redirects to the calendar handler:
The class is:
And i am really confused because it seems to return correct data:
I guess I am missing something....? Any help would be greatly appreciated.
The initial page loads:
<!DOCTYPE html>
<
html
>
<
head
>
<
title
></
title
>
<
link
href
=
"../kendo/styles/kendo.common.min.css"
rel
=
"stylesheet"
/>
<
link
href
=
"../kendo/styles/kendo.default.min.css"
rel
=
"stylesheet"
/>
<
script
src
=
"../kendo/js/jquery.min.js"
></
script
>
<
script
src
=
"../kendo/js/kendo.all.min.js"
></
script
>
</
head
>
<
script
>
$(document).ready(function(){
$.ajax({
type: "POST",
dataType: "html",
data: {
request: 'calendar'
},
url: "../ajaxlistener.php",
cache: false,
success: function (data) {
$("#cal").html(data);
}
});
});
</
script
>
<
style
scoped>
#people {
background: url('i/2oa8kvmz.bmp') transparent no-repeat;
height: 115px;
position: relative;
}
#alex {
position: absolute;
left: 404px;
top: 81px;
}
#bob {
position: absolute;
left: 519px;
top: 81px;
}
#charlie {
position: absolute;
left: 634px;
top: 81px;
}
</
style
>
<
body
>
<
div
id
=
"people"
>
<
input
checked
type
=
"checkbox"
id
=
"alex"
value
=
"1"
>
<
input
checked
type
=
"checkbox"
id
=
"bob"
value
=
"2"
>
<
input
type
=
"checkbox"
id
=
"charlie"
value
=
"3"
>
</
div
>
<
div
id
=
"cal"
>
</
div
>
</
body
>
</
html
>
include
(
"includes/calendar.class.php"
);
$cal
=
new
calendar();
if
(!isset(
$_GET
[
'action'
])){
echo
$cal
->makeCalBase();
}
else
{
$rawData
= json_decode(
file_get_contents
(
'php://input'
));
$action
=
$_GET
[
'action'
];
if
(
$action
==
'read'
){
echo
$cal
->loadCal();
}
elseif
(
$action
==
'create'
){
echo
$cal
->saveCal(
$rawData
);
}
<?php
class
calendar
{
private
$uid
;
private
$calendarid
;
private
$today
;
private
$sched
;
private
$rawData
=
array
();
private
$json
;
private
$timezone
=
""
;
public
$display
;
public
function
date_normalizer(
$d
)
{
if
(
$d
instanceof DateTime) {
return
$d
->getTimestamp();
}
else
{
return
strtotime
(
$d
);
}
}
private
function
getLocations()
{
$rArray
=
array
();
$get
=
"SELECT location_id, name, address1 FROM locations ORDER BY location_id ASC"
;
$exe
=
new
Query(
$get
,
__LINE__
,
__FILE__
);
$x
= 0;
while
(
$r
=
$exe
->fetch_assoc_array()) {
$rArray
[
$x
][
'text'
] = ucwords(
$r
[
'name'
]);
$rArray
[
$x
][
'value'
] =
$r
[
'location_id'
];
if
(trim(
$r
[
'address1'
]) !=
""
) {
$rArray
[
$x
][
'color'
] =
"#"
.
substr
(sha1(
$r
[
'address1'
]), 0, 6);
}
else
{
$rArray
[
$x
][
'color'
] =
"#"
.
substr
(sha1(time() *
$r
[
'location_id'
]), 0, 6);
}
$x
++;
}
return
$rArray
;
}
public
function
makeCalBase()
{
$transport
=
new
\Kendo\Data\DataSourceTransport();
$create
=
new
\Kendo\Data\DataSourceTransportCreate();
$create
->url(
'../calendarcontrol.php?action=create'
)
->contentType(
'application/json'
)
->type(
'POST'
);
$read
=
new
\Kendo\Data\DataSourceTransportRead();
$read
->url(
'../calendarcontrol.php?action=read'
)
->contentType(
'application/json'
)
->type(
'POST'
);
$update
=
new
\Kendo\Data\DataSourceTransportUpdate();
$update
->url(
'../calendarcontrol.php?action=update'
)
->contentType(
'application/json'
)
->type(
'POST'
);
$destroy
=
new
\Kendo\Data\DataSourceTransportDestroy();
$destroy
->url(
'../calendarcontrol.php?action=destroy'
)
->contentType(
'application/json'
)
->type(
'POST'
);
$transport
->create(
$create
)
->read(
$read
)
->update(
$update
)
->destroy(
$destroy
)
->parameterMap('
function
(data) {
return
kendo.stringify(data);
}');
$model
=
new
\Kendo\Data\DataSourceSchemaModel();
$taskIDField
=
new
\Kendo\Data\DataSourceSchemaModelField(
'taskID'
);
$taskIDField
->type(
'number'
)
->from(
'entry_id'
)
->nullable(true);
$titleField
=
new
\Kendo\Data\DataSourceSchemaModelField(
'title'
);
$titleField
->from(
'event_title'
)
->defaultValue(
'No title'
)
->validation(
array
(
'required'
=> true));
$startField
=
new
\Kendo\Data\DataSourceSchemaModelField(
'start'
);
$startField
->type(
'date'
)
->from(
'start_time'
);
$startTimezoneField
=
new
\Kendo\Data\DataSourceSchemaModelField(
'startTimezone'
);
$startTimezoneField
->from(
'start_timezone'
);
$endField
=
new
\Kendo\Data\DataSourceSchemaModelField(
'end'
);
$endField
->type(
'date'
)
->from(
'end_time'
);
$endTimezoneField
=
new
\Kendo\Data\DataSourceSchemaModelField(
'endTimezone'
);
$endTimezoneField
->from(
'end_timezone'
);
$isAllDayField
=
new
\Kendo\Data\DataSourceSchemaModelField(
'isAllDay'
);
$isAllDayField
->type(
'boolean'
)
->from(
'all_day'
);
$descriptionField
=
new
\Kendo\Data\DataSourceSchemaModelField(
'description'
);
$descriptionField
->type(
'string'
)
->from(
'details'
);
$recurrenceIdField
=
new
\Kendo\Data\DataSourceSchemaModelField(
'recurrenceId'
);
$recurrenceIdField
->from(
'recure_id'
);
$recurrenceRuleField
=
new
\Kendo\Data\DataSourceSchemaModelField(
'recurrenceRule'
);
$recurrenceRuleField
->from(
'recure_rule'
);
$recurrenceExceptionField
=
new
\Kendo\Data\DataSourceSchemaModelField(
'recurrenceException'
);
$recurrenceExceptionField
->from(
'recure_exception'
);
$ownerIdField
=
new
\Kendo\Data\DataSourceSchemaModelField(
'ownerId'
);
$ownerIdField
->from(
'location_id'
)
->defaultValue(0);
$model
->id(
'entry_id'
)
->addField(
$taskIDField
)
->addField(
$titleField
)
->addField(
$startField
)
->addField(
$endField
)
->addField(
$startTimezoneField
)
->addField(
$endTimezoneField
)
->addField(
$descriptionField
)
->addField(
$recurrenceIdField
)
->addField(
$recurrenceRuleField
)
->addField(
$recurrenceExceptionField
)
->addField(
$ownerIdField
)
->addField(
$isAllDayField
);
$schema
=
new
\Kendo\Data\DataSourceSchema();
$schema
->data(
'data'
)
->errors(
'errors'
)
->model(
$model
);
$dataSource
=
new
\Kendo\Data\DataSource();
$dataSource
->transport(
$transport
)
->schema(
$schema
)
->batch(true)
->addFilterItem(
array
(
'logic'
=>
'or'
,
'filters'
=>
array
(
array
(
'field'
=>
'owner_id'
,
'operator'
=>
'eq'
,
'value'
=> 1),
array
(
'field'
=>
'owner_id'
,
'operator'
=>
'eq'
,
'value'
=> 2),
)
));
$resource
=
new
\Kendo\UI\SchedulerResource();
$resource
->field(
'owner_id'
)
->title(
'owner_id'
)
->dataSource(
$this
->getLocations());
$scheduler
=
new
\Kendo\UI\Scheduler(
'scheduler'
);
$scheduler
->timezone(
"Etc/UTC"
)
->
date
(
new
DateTime())
->height(600)
->addResource(
$resource
)
->addView(
array
(
'type'
=>
'day'
,
'startTime'
=>
new
DateTime()),
array
(
'type'
=>
'week'
,
'selected'
=> true,
'startTime'
=>
new
DateTime()),
'month'
,
'agenda'
)
->dataSource(
$dataSource
);
return
$scheduler
->render();
}
public
function
makeEmptyCal()
{
}
public
function
saveCal(
$data
)
{
$insertData
=
array
(
array
());
$queryList
=
""
;
foreach
(
$data
->models AS
$uselessVar
=>
$usableData
) {
$dataArray
= get_object_vars(
$usableData
);
if
(
$dataArray
[
'entry_id'
] !== null) {
}
else
{
$cols
=
"("
;
$values
=
"("
;
foreach
(
$dataArray
AS
$field
=>
$val
) {
if
(
$field
==
"start_time"
||
$field
==
"end_time"
) {
$val
=
date
(
"Y-m-d H:i:s"
,
$this
->date_normalizer(
$val
));
}
if
(
$field
!=
'entry_id'
) {
$cols
.=
"{$field},"
;
$values
.=
"'"
. trim(
$val
) .
"',"
;
}
}
$cols
.=
"owner_id)"
;
$values
.=
"{$this->uid})"
;
$queryList
.=
"INSERT INTO scheduler_data {$cols} VALUES {$values};\n"
;
}
}
if
(
$queryList
!=
""
) {
new
Query(
$queryList
,
__LINE__
,
__FILE__
);
}
return
$this
->loadCal();
}
public
function
loadCal()
{
$getData
=
"SELECT entry_id, event_title, start_time, end_time, all_day, details, recure_id, recure_rule, recure_exception, location_id FROM scheduler_data WHERE owner_id = 0 OR owner_id = {$this->uid}"
;
$exe
=
new
Query(
$getData
,
__LINE__
,
__FILE__
);
$returnObject
=
new
stdClass();
$returnObject
->models =
array
();
$x
=0;
while
(
$r
=
$exe
->fetch_assoc_array()) {
$returnObject
->models[
$x
] =
new
stdClass();
foreach
(
$r
AS
$c
=>
$v
) {
$c
=
str_replace
(
array
(
"entry_id"
,
"event_title"
,
"start_time"
,
"end_time"
,
"all_day"
,
"details"
,
"recure_id"
,
"recure_rule"
,
"recure_exception"
,
"location_id"
),
array
(
"TaskID"
,
"Title"
,
"Start"
,
"End"
,
"IsAllDay"
,
"Description"
,
"RecurrenceRule"
,
"RecurrenceID"
,
"RecurrenceException"
,
"OwnerID"
),
$c
);
if
(
$c
!=
'start_time'
&&
$c
!=
'end_time'
&&
$c
!=
"Start"
&&
$c
!=
"End"
){
$v
= trim(
stripslashes
(
$v
));
if
(
$v
==
""
){
$v
= null;
}
if
(preg_match(
"/_id/"
,
$c
) || preg_match(
"/ID/"
,
$c
)){
$returnObject
->models[
$x
]->
$c
=
intval
(
$v
);
}
elseif
(
$c
==
'all_day'
){
if
(
$v
==
'0'
){
$returnObject
->models[
$x
]->
$c
= false;
}
else
{
$returnObject
->models[
$x
]->
$c
= true;
}
}
else
{
$returnObject
->models[
$x
]->
$c
=
$v
;
}
}
else
{
$returnObject
->models[
$x
]->
$c
=
"/Date("
.
$this
->date_normalizer(
$v
) .
")/"
;
}
}
$x
++;
}
return
"jQuery("
. json_encode(
$returnObject
->models) .
")"
;
}
function
__construct(
$cid
= 0)
{
$this
->calendarid =
$cid
;
$this
->uid =
$_SESSION
[
'user_id'
];
$this
->today = time();
}
}
?>
jQuery([{
"entry_id"
:1,
"event_title"
:
"Test Event"
,
"start_time"
:
"\/Date(1376840734)\/"
,
"end_time"
:
"\/Date(1376842534)\/"
,
"all_day"
:
false
,
"details"
:
null
,
"recure_id"
:0,
"recure_rule"
:
null
,
"recure_exception"
:
null
,
"location_id"
:0},{
"entry_id"
:2,
"event_title"
:
"Another Event"
,
"start_time"
:
"\/Date(1377006334)\/"
,
"end_time"
:
"\/Date(1377008134)\/"
,
"all_day"
:
false
,
"details"
:
"Some more info about that event"
,
"recure_id"
:0,
"recure_rule"
:
null
,
"recure_exception"
:
null
,
"location_id"
:0},{
"entry_id"
:3,
"event_title"
:
"Test Event"
,
"start_time"
:
"\/Date(1376919934)\/"
,
"end_time"
:
"\/Date(1376921734)\/"
,
"all_day"
:
false
,
"details"
:
"This is a test event"
,
"recure_id"
:0,
"recure_rule"
:
null
,
"recure_exception"
:
null
,
"location_id"
:0},{
"entry_id"
:4,
"event_title"
:
"DATA!!"
,
"start_time"
:
"\/Date(1377024633)\/"
,
"end_time"
:
"\/Date(1377026433)\/"
,
"all_day"
:
false
,
"details"
:
null
,
"recure_id"
:0,
"recure_rule"
:
null
,
"recure_exception"
:
null
,
"location_id"
:0},{
"entry_id"
:5,
"event_title"
:
"DATA!!"
,
"start_time"
:
"\/Date(1377024633)\/"
,
"end_time"
:
"\/Date(1377026433)\/"
,
"all_day"
:
false
,
"details"
:
null
,
"recure_id"
:0,
"recure_rule"
:
null
,
"recure_exception"
:
null
,
"location_id"
:0},{
"entry_id"
:6,
"event_title"
:
"asdfasdfasdf"
,
"start_time"
:
"\/Date(1377021033)\/"
,
"end_time"
:
"\/Date(1377022833)\/"
,
"all_day"
:
false
,
"details"
:
null
,
"recure_id"
:0,
"recure_rule"
:
null
,
"recure_exception"
:
null
,
"location_id"
:0},{
"entry_id"
:7,
"event_title"
:
"asdasdasd"
,
"start_time"
:
"\/Date(1376845910)\/"
,
"end_time"
:
"\/Date(1376847710)\/"
,
"all_day"
:
false
,
"details"
:
null
,
"recure_id"
:0,
"recure_rule"
:
null
,
"recure_exception"
:
null
,
"location_id"
:0},{
"entry_id"
:8,
"event_title"
:
"No title"
,
"start_time"
:
"\/Date(1376784000)\/"
,
"end_time"
:
"\/Date(1376784000)\/"
,
"all_day"
:
true
,
"details"
:
null
,
"recure_id"
:0,
"recure_rule"
:
null
,
"recure_exception"
:
null
,
"location_id"
:0},{
"entry_id"
:9,
"event_title"
:
"No title"
,
"start_time"
:
"\/Date(1376784000)\/"
,
"end_time"
:
"\/Date(1376784000)\/"
,
"all_day"
:
true
,
"details"
:
null
,
"recure_id"
:0,
"recure_rule"
:
null
,
"recure_exception"
:
null
,
"location_id"
:0},{
"entry_id"
:10,
"event_title"
:
"asdasdasd"
,
"start_time"
:
"\/Date(1376939633)\/"
,
"end_time"
:
"\/Date(1376941433)\/"
,
"all_day"
:
false
,
"details"
:
null
,
"recure_id"
:0,
"recure_rule"
:
null
,
"recure_exception"
:
null
,
"location_id"
:0},{
"entry_id"
:11,
"event_title"
:
"Some Event"
,
"start_time"
:
"\/Date(1377026532)\/"
,
"end_time"
:
"\/Date(1377028332)\/"
,
"all_day"
:
false
,
"details"
:
null
,
"recure_id"
:0,
"recure_rule"
:
null
,
"recure_exception"
:
null
,
"location_id"
:0},{
"entry_id"
:12,
"event_title"
:
"Yet another event!"
,
"start_time"
:
"\/Date(1377031457)\/"
,
"end_time"
:
"\/Date(1377033257)\/"
,
"all_day"
:
false
,
"details"
:
"Some info aout said event"
,
"recure_id"
:0,
"recure_rule"
:
null
,
"recure_exception"
:
null
,
"location_id"
:0}])
I guess I am missing something....? Any help would be greatly appreciated.