From 9d46b7d8919986c241ee6bb7886994c6c2d0e9b8 Mon Sep 17 00:00:00 2001 From: cos Date: Sat, 4 Apr 2015 13:25:18 +0200 Subject: Enable setting multiple dishes per meal. --- mat | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/mat b/mat index dfd3d21..3fa9d8c 100755 --- a/mat +++ b/mat @@ -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; -- cgit v1.2.3