Hi
I need to make something like a task scheduler in my nuBuilder project.
I have some cars and I need to make a planning for maintenance.
So I created a subform that refers to a table with these columns: car_id, date, maintenance type (oil, tyres, etc.) and a boolean field, default '0', that becomes '1' when the maintenance is done.
But since I need to do maintenance every year, I'm searching for a function that inserts a new task with same values but date increased by one year when the previous task is done.
I tried to create a button on subform to do this, but I think it's not possible to run a sql query from JavaScript to insert a new row in the maintenance table.
Neither I know a way to run PHP from a button.
Other possibilities are:
1) Populate the field directly on subform in javascript, then save the record, but I don't know how insert a new subform row from javascript.
2) Use a PHP procedure (Add Activity) to insert new row directly into the database (nuRunQuery), but it seems too intricate and it opens a new blank window... comfortless!
3) Implement a cron job that does the task each year at 1st january.
Any suggestions?
Thank you
Alex
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Suggestions for making a task scheduler
-
- Posts: 38
- Joined: Tue Jun 05, 2012 2:40 pm
- Location: Bologna, Italy
- Contact:
Re: Suggestions for making a task scheduler
Alex,
The best answer is to create a new record in After Save of the Form
Something like this..
Hope this helps
Steven
The best answer is to create a new record in After Save of the Form
Something like this..
Code: Select all
if('#finished_date#' != '' && '#finished#' != '1'){ //-- finished_date has just been added
$id = uniqid('1');
nuRunQuery("UPDATE service SET finished = '1' WHERE service_id = '#newID#'");
nuRunQuery("INSERT INTO service (service_id, car_id, due) VALUES ('$id', '#car_id#', DATE_ADD('#finished_date#', INTERVAL 1 YEAR);));
}
Steven
-
- Posts: 38
- Joined: Tue Jun 05, 2012 2:40 pm
- Location: Bologna, Italy
- Contact:
Re: Suggestions for making a task scheduler
Steve
I had to modify the code because data are on a subform.
Furthermore I need some data that isn't displayed on the subform but is stored into database.
So I modified the code this way:
and it works.
Thank you for your suggestions.
Alex
I had to modify the code because data are on a subform.
Furthermore I need some data that isn't displayed on the subform but is stored into database.
So I modified the code this way:
Code: Select all
$s = "scadenze_auto";
$rows = $_POST["rows" . $s];
$table = nuRunQuery("SELECT tt_autoscad_idauto, tt_autoscad_id, tt_autoscad_data FROM tt_auto_scadenze");
for($i = 0 ; $i < $rows ; $i ++){
$field1 = 'scadenze_auto' . substr('000'.$i, -4) . 'tt_autoscad_datafin';
$field2 = 'scadenze_auto' . substr('000'.$i, -4) . 'tt_autoscad_stato';
$field3 = 'scadenze_auto' . substr('000'.$i, -4) . 'tt_autoscad_data';
$field4 = 'scadenze_auto' . substr('000'.$i, -4) . 'tt_autoscad_idtip';
$field5 = 'scadenze_auto' . substr('000'.$i, -4) . 'tt_autoscad_note';
$r = db_fetch_row($table);
$f1 = $_POST[$field1];
$f2 = $_POST[$field2];
$f3 = $_POST[$field3];
$f4 = $_POST[$field4];
$f5 = $_POST[$field5];
if($f1 != '' && $f3 != '' && $f2 != 'Sì'){
$id = uniqid('1');
nuRunQuery("UPDATE tt_auto_scadenze SET tt_autoscad_stato = 'Sì' WHERE tt_autoscad_id = '$r[1]'");
$sql = "INSERT INTO tt_auto_scadenze (tt_autoscad_id, tt_autoscad_idauto, tt_autoscad_data, tt_autoscad_idtip, tt_autoscad_note, tt_autoscad_stato)";
$sql .= " VALUES ('$id', '$r[0]', DATE_ADD('$r[2]', INTERVAL 1 YEAR), '$f4', '$f5', 'No')";
nuRunQuery($sql);
Thank you for your suggestions.
Alex