Categories | Question details Back To List | ||
Updating MySQL Unix date tables with Scheduler I managed to get the Scheduler to display the dates correctly but it doesn't update the database when I make a change in the Scheduler here is my code so far: include ('../config.php'); include ('../../codebase/scheduler_connector.php'); $res=mysql_connect($mysql_server,$mysql_user,$mysql_pass); mysql_select_db($mysql_db); $scheduler = new schedulerConnector($res); $scheduler->enable_log("log.txt",true); $scheduler->render_sql("select id,from_unixtime(sessdate) AS start,from_unixtime(sessionend) AS finish,description from mdl_attendance_sessions","id","start,finish,description"); The Scheduler is a wonderful tool and I hope you can help me to update my tables. Thanks Answer posted by Alex (support) on Sep 17, 2009 07:59 You can set beforeInsert and beforeUpdate event handler to call custom code. http://dhtmlx.com/dhxdocs/doku.php?id=dhtmlxconnector:events_system http://dhtmlx.com/dhxdocs/doku.php?id=dhtmlxconnector:event_beforeupdate Answer posted by Barry on Sep 17, 2009 09:46 Thanks for the help. I tried to implement the beforeupdate event handler but am still not able to update tables: here is my code: <?php include ('../config.php'); include ('../../codebase/scheduler_connector.php'); $res=mysql_connect($mysql_server,$mysql_user,$mysql_pass); mysql_select_db($mysql_db); $scheduler = new schedulerConnector($res); $scheduler->enable_log("log.txt",true); function myUpdate($action){ mysql_query("UPDATE mdl_attendance_sessions SET sessdate = '{strtotime($action->get_value('sessdate'))}', sessionend = '{strtotime($action->get_value('sessionend'))}', description = '{$action->get_value('description')}' WHERE id='{$action->get_id()}'"); $action->success(); } $scheduler->event->attach("beforeUpdate","myUpdate"); $scheduler->render_sql("select id,from_unixtime(sessdate) AS sessdate,from_unixtime(sessionend) AS sessionend,description from mdl_attendance_sessions","id","sessdate,sessionend,description"); ?> and here is the text from the log file: DataProcessor object initialized 346_id => 346 346_start_date => 2009-9-10 16:40 346_end_date => 2009-9-10 17:05 346_text => 346_!nativeeditor_status => updated ids => 346 Row data [346] id => 346 sessdate => 2009-9-10 16:40 sessionend => 2009-9-10 17:05 description => !nativeeditor_status => updated Undefined property: DataAction::$get_value at /home/admin/public_html/test/mod/attforblock/dhtmlx/dhtmlxConnector/php/samples/scheduler/events.php line 13 Undefined property: DataAction::$get_value at /home/admin/public_html/test/mod/attforblock/dhtmlx/dhtmlxConnector/php/samples/scheduler/events.php line 13 Event code for update processed Edit operation finished 0 => action:updated; sid:346; tid:346; Answer posted by Barry on Sep 17, 2009 15:03 Update: I got it to work like this: <?php include ('../config.php'); include ('../../codebase/scheduler_connector.php'); $res=mysql_connect($mysql_server,$mysql_user,$mysql_pass); mysql_select_db($mysql_db); $scheduler = new schedulerConnector($res); $scheduler->enable_log("log.txt",true); function myUpdate($action){ $start = strtotime($action->get_value('sessdate')); $finish = strtotime($action->get_value('sessionend')); mysql_query("UPDATE mdl_attendance_sessions SET sessdate = '{$start}', sessionend = '{$finish}', description = '{$action->get_value('description')}' WHERE id='{$action->get_id()}'"); $action->success(); } $scheduler->event->attach("beforeUpdate","myUpdate"); $scheduler->render_sql("select id,from_unixtime(sessdate) AS sessdate,from_unixtime(sessionend) AS sessionend,description from mdl_attendance_sessions","id","sessdate,sessionend,description"); ?> Great stuff! |