diff --git a/lib/calcms/series_dates.pm b/lib/calcms/series_dates.pm index 3df09a9..9eb53b0 100644 --- a/lib/calcms/series_dates.pm +++ b/lib/calcms/series_dates.pm @@ -416,7 +416,7 @@ sub get_week_of_month_dates{ return undef if $frequency eq''; return undef if $frequency==0; - my $start_dates=time::get_nth_weekday_in_month($start, $end, $week, $weekday-1); + my $start_dates=time::get_nth_weekday_in_month($start, $end, $week, $weekday); if ((defined $nextDay) && ($nextDay>0)){ for (my $i=0;$i<@$start_dates;$i++){ diff --git a/lib/calcms/time.pm b/lib/calcms/time.pm index 0a5a118..c8e8285 100644 --- a/lib/calcms/time.pm +++ b/lib/calcms/time.pm @@ -24,7 +24,7 @@ our @EXPORT_OK = qw( date_cond time_cond check_date check_time check_datetime check_year_month datetime_to_rfc822 get_datetime datetime_to_utc datetime_to_utc_datetime get_duration get_duration_seconds - get_durations get_names get_all_names get_weekdays weekday_index + get_durations get_names get_all_names weekday_index $names ); @@ -86,24 +86,24 @@ our $weekday_index={ sub get_weekdays{ return{ - 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, - 'Mo'=>0, - 'Tu'=>1, - 'Di'=>1, - 'We'=>2, - 'Mi'=>2, - 'Th'=>3, - 'Do'=>3, - 'Fr'=>4, - 'Sa'=>5, - 'Su'=>6, - 'So'=>6 + 7 => 7, + 'Mo'=>1, + 'Tu'=>2, + 'Di'=>2, + 'We'=>3, + 'Mi'=>3, + 'Th'=>4, + 'Do'=>4, + 'Fr'=>5, + 'Sa'=>6, + 'Su'=>7, + 'So'=>7 }; } @@ -518,14 +518,15 @@ sub get_event_date{ my $datetime=time::time_to_datetime(time()); my $hour=(time::datetime_to_array($datetime))->[3]; + #print STDERR "datetime=$datetime hour=$hour\n"; #today: between 0:00 and starting_hour show last day if ($hour < $config->{date}->{day_starting_hour}){ - my $date=time::datetime_to_array(time::add_hours_to_datetime($datetime,-24)); - return $date->[0].'-'.$date->[1].'-'.$date->[2]; + my $date=time::datetime_to_array(time::add_days_to_datetime($datetime,-1)); + return join('-', ($date->[0], $date->[1], $date->[2]) ); }else{ #today: between starting_hour and end of day show current day my $date=time::datetime_to_array(time::time_to_datetime(time())); - return $date->[0]."-".$date->[1]."-".$date->[2]; + return join('-', ($date->[0], $date->[1], $date->[2]) ); } } @@ -559,15 +560,22 @@ sub get_datetime{ #get list of nth weekday in month from start to end sub get_nth_weekday_in_month{ - my $start=shift; # datetime string - my $end=shift; # datetime string - my $nth=shift; # every nth week of month - my $weekday=shift; # weekday [0..6,'Mo'-'Su','Mo'-'Fr'] + my $start = shift; # datetime string + my $end = shift; # datetime string + my $nth = shift; # every nth week of month + my $weekday = shift; # weekday [1..7,'Mo'-'Su','Mo'-'Fr'] - my $weekdays=time::get_weekdays(); - $weekday=$weekdays->{$weekday+1}; + return [] unless defined $start; + return [] unless defined $end; + return [] unless defined $nth; + return [] unless defined $weekday; + + my $weekdays = time::get_weekdays(); + return [] unless defined $weekdays->{$weekday}; + $weekday = $weekdays->{$weekday}; my $dates=[]; + if ($start=~/(\d\d\d\d)-(\d\d)-(\d\d)[ T](\d\d)\:(\d\d)/){ my $hour=int($4); my $min=int($5); diff --git a/lib/calcms/uac.pm b/lib/calcms/uac.pm index 9b312d3..754ee98 100644 --- a/lib/calcms/uac.pm +++ b/lib/calcms/uac.pm @@ -57,15 +57,31 @@ sub get_user{ # get all users sub get_users{ - my $config=shift; + my $config = shift; + my $condition = shift; + + my @conditions=(); + my @bind_values=(); + + for my $key ('name', 'email'){ + my $value = $condition->{$key}; + next unless defined $value; + next if $value eq ''; + push @conditions, $key.'=?'; + push @bind_values, $value; + } + + my $conditions=''; + $conditions=" where ".join(" and ",@conditions) if (scalar @conditions>0); my $query=qq{ select id, name, full_name, email, disabled, modified_at, created_at from calcms_users + $conditions }; - my $dbh=db::connect($config); - my $users=db::get($dbh, $query); + my $dbh = db::connect($config); + my $users = db::get($dbh, $query, \@bind_values); return $users; } @@ -93,7 +109,7 @@ sub get_users_by_studio{ } my $conditions=''; - $conditions=" and ".join(" and ",@conditions) if (@conditions>0); + $conditions=" and ".join(" and ",@conditions) if (scalar @conditions>0); my $query=qq{ select distinct(u.id), u.name, u.full_name @@ -808,9 +824,11 @@ sub print_warn{ } sub print_error{ + my $message=shift; + print STDERR "ERROR:".$message."\n"; print '