diff options
author | cos <cos> | 2015-04-04 13:25:18 +0200 |
---|---|---|
committer | cos <cos> | 2015-04-04 13:25:18 +0200 |
commit | 9d46b7d8919986c241ee6bb7886994c6c2d0e9b8 (patch) | |
tree | d1f875e3b702ffc68287dae345ffd1409435a702 | |
parent | 341364c7a7882a5e05a0fb6a13efb4a51df3772a (diff) | |
download | mat-feature/multimeal.zip |
Enable setting multiple dishes per meal.feature/multimeal
-rwxr-xr-x | mat | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -124,7 +124,7 @@ my @schedule = ( ); sub cmd_setmeal { - my ( $date, $mealtype, $recipe_id ) = @_; + my ( $date, $mealtype, $recipe_ids ) = @_; if ($date =~ /^Mon|Tue|Wed|Thu|Fri|Sat|Sun/) { my $wday; @@ -146,13 +146,17 @@ sub cmd_setmeal { return unless $mealtype =~ "^(frukost)|(elvakaffe)|(lunch)|(fruktstund)|(middag)\$"; return unless $date =~ "^[0-9]{4}-[0-9]{2}-[0-9]{2}\$"; - return -1 unless $recipe_id =~ m/^[0-9]+$|^-$/; + return -1 unless $recipe_ids =~ m/^[0-9+]+$|^-$/; my $sql = "DELETE FROM plan WHERE date='$date' and mealtype='$mealtype';"; $db->do($sql); - if ($recipe_id ne '-' && get_recipe_name($recipe_id) ne 'NULL') { - $sql = "INSERT INTO plan (date, mealtype, recipe_id) VALUES ('$date', - '$mealtype', $recipe_id);"; - $db->do($sql); + + for my $recipe_id (split('\+', $recipe_ids)) + { + if ($recipe_id ne '-' && get_recipe_name($recipe_id) ne 'NULL') { + $sql = "INSERT INTO plan (date, mealtype, recipe_id) VALUES ('$date', + '$mealtype', $recipe_id);"; + $db->do($sql); + } } return 0; |