diff options
-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; |