Hello there,
I’m new to dhtmlx and after spending a good ammount of time reading the docs I am still having trouble saving a new event from the calendar into the database. More specifically it seems no save event is being passed to the db connector. This is my PHP file that handles the databaseconnector
[code]<?
include ('library/javascript/calendar/codebase/connector/scheduler_connector.php');
$e3 = new Employees;
$sql = readdbconn();
$res = mysql_connect($sql[0],$sql[1],$sql[2]);// db connection
mysql_select_db($sql[3]); // db connection
$calendar = new SchedulerConnector($res, "MySQL");
//$calendar->enable_log("log.txt",true);
if ($calendar->is_select_mode()) {
//This works and reads the database
$query = ...Big ol' MySQL query...
$calendar->render_sql($query, "id", "event_start,event_end,text,staffcount,roleid");
}
else {
//This part echos when "saving"
echo "Attempting to Save";
$calendar->event->attach("beforeInsert","CreateShift"); //This event doesn't fire?!
}
function CreateShift($action) {
//This event NEVER gets fired?!?!
$query = "INSERT INTO `schedule_planned` (`date`) VALUES(NOW())";
//mysql_query($query);
echo "Database Query";
}
?>[/code]
When saving the new calendar event my custom function CreateShift is not getting triggered. Why am I missing in my Javascript for the Calendar?
[code]$(document).ready(function() {
if ($("#scheduler_here").length) {
RunWeatherApp();
if ($("#scheduler_here").hasClass("create")) {
var createMode = true;
//Creating new schedules
scheduler.attachEvent("onTemplatesReady", function(){
scheduler.templates.event_text=function(start,end,event){
return "<b>" + event.text + " (" + event.staffcount + ")</b><br>";
}
});
scheduler.form_blocks["my_editor"] = {
render:function(sns) {
if ($(roles).length > 0) {
var option = '';
for (i = 0; i < $(roles).length; i++){
option += '<option value="'+ roles[i]['value'] + '">' + roles[i]['text'] + '</option>';
}
return "<div class='dhx_cal_ltext' style='height:60px;'><label>Position</label><select name='role'>" + option + "</select><br/><label># of Staff</label><input name='count' type='number'></div>";
}
else {
return "<div class='dhx_cal_ltext'><h2 class='bubble'>You don't have any active staff members to schedule</h2></div>";
}
},
set_value:function(node, value, ev) {
$(node).find("select").val(ev.roleid);
$(node).find("input").val(ev.staffcount);
},
get_value:function(node, ev) {
ev.staffcount = $(node).find("input").val();
return $(node).find("select option:selected").text();
},
focus:function(node) {
var a = node.childNodes[1];
//a.select();
a.focus();
}
};
scheduler.config.lightbox.sections=[
{ name:"Shift", height:200, map_to:"text", type:"my_editor" , focus:true}
]
}
else {
var createMode = false;
//Assigning shifts
scheduler.attachEvent("onTemplatesReady", function(){
scheduler.templates.event_text=function(start,end,event){
return "<b>" + event.text + " (" + event.assigned + "/" + event.staffcount + " Assigned)</b><br>";
}
});
scheduler.attachEvent("onBeforeDrag", function(){
return false;
})
}
//Standard init
scheduler.config.details_on_dblclick = true; //Create details view on double click
scheduler.config.details_on_create = true; //Create details view on create
scheduler.config.first_hour = 6;
scheduler.config.last_hour = 24;
//Weather Setup
scheduler.attachEvent("onViewChange", function (new_mode , new_date) { RunWeatherApp(); });
var DisplayFormat = scheduler.date.date_to_str(scheduler.config.day_date);
var ComputeFormat = scheduler.date.date_to_str("%d-%m-%Y");
scheduler.templates.week_scale_date = function(date){
return DisplayFormat(date) + "<aside class='weather' data-date='" + ComputeFormat(date) + "'></aside>";
};
scheduler.init('scheduler_here', new Date(),"week");
if (createMode) {
scheduler.load("/ui/schedule/");
var dp = new dataProcessor("/?view=ui&var1=schedule");
scheduler.EnableDataprocessor = true;
}
else {
scheduler.load("/ui/assign/");
var dp = new dataProcessor("/?view=ui&var1=assign");
}
//Disable Saving Attempt
dp.init(scheduler);
}
});[/code]
Please help, thanks!
Brian