Skip to content

Commit

Permalink
Merge pull request #50 from brlumen/fix-current-week
Browse files Browse the repository at this point in the history
Fixing date error for new year
  • Loading branch information
brlumen authored Jan 5, 2022
2 parents 61d11a4 + 21d0bab commit b26236c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Calendar/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function register() {
$this->description = plugin_lang_get( 'description' );
$this->page = 'config_page';

$this->version = '2.6.0';
$this->version = '2.6.1';

$this->requires = array(
'MantisCore' => '2.14.0',
Expand Down
25 changes: 19 additions & 6 deletions Calendar/core/calendar_date_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,35 @@
# along with Customer management plugin for MantisBT.
# If not, see <http://www.gnu.org/licenses/>.

function days_of_number_week( $p_start_step_days, $p_count_step_days, $t_week_days_name, $p_week = null ) {
function timestamp_next_week_get( $p_week, $p_year ) {
return strtotime( $p_year . 'W' . str_pad( $p_week, 2, 0, STR_PAD_LEFT ) . ' + 1 weeks' );
}

function timestamp_previous_week_get( $p_week, $p_year ) {
return strtotime( $p_year . 'W' . str_pad( $p_week, 2, 0, STR_PAD_LEFT ) . ' - 1 weeks' );
}

function days_of_number_week( $p_start_step_days, $p_count_step_days, $t_week_days_name, $p_week = null, $p_year = null ) {

if( $p_week == null ) {
$t_week = date( "e" );
$t_week = date( "W" );
}

$t_week = str_pad( $p_week, 2, 0, STR_PAD_LEFT );

if( $p_year == null ) {
$p_year = date( "Y" );
}

$t_week = $p_week - 1;
$t_curent_years = date( "Y" );
$t_days_week = array();

for( $i = $p_start_step_days; $i < $p_start_step_days + $p_count_step_days; $i++ ) {

$t_day_cheks = date( "D", strtotime( 'last monday + ' . $i . ' days 1/1/' . $t_curent_years . ' + ' . $t_week . ' weeks' ) );
$t_process_time = strtotime( $p_year . 'W' . $t_week . ' + ' . $i . ' days' );
$t_day_cheks = date( "D", $t_process_time );

if( $t_week_days_name[$t_day_cheks] == ON ) {
$t_days_week[$i] = date( strtotime( 'last monday + ' . $i . ' days 1/1/' . $t_curent_years . ' + ' . $t_week . ' weeks' ) );
$t_days_week[$i] = date( $t_process_time );
}
}
return $t_days_week;
Expand Down
17 changes: 10 additions & 7 deletions Calendar/core/classes/ViewWeekCalendar.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
class ViewWeekCalendar extends WeekCalendar {
protected $week;
protected $for_user;
protected $year;

//put your code here
public function __construct( $p_week, $p_user, $p_is_full_time, $p_days_events, $p_link_options ) {
public function __construct( $p_week, $p_user, $p_is_full_time, $p_days_events, $p_link_options, $p_year ) {
parent::__construct($p_days_events, $p_link_options, $p_is_full_time);

$this->week = $p_week;
$this->for_user = (int)$p_user;
$this->year = $p_year;
}

protected function print_spacer_top() {
Expand Down Expand Up @@ -53,21 +55,21 @@ protected function print_menu_top() {

echo '<div class="btn-group pull-left">';
if( self::$full_time_is == FALSE ) {
print_small_button( plugin_page( 'calendar_user_page' ) . "&for_user=" . $this->for_user . "&week=" . $this->week . "&full_time=TRUE", "0-24" );
print_small_button( plugin_page( 'calendar_user_page' ) . "&for_user=" . $this->for_user . "&week=" . $this->week . "&year=" . $this->year . "&full_time=TRUE", "0-24" );
} else {
print_small_button( plugin_page( 'calendar_user_page' ) . "&for_user=" . $this->for_user . "&week=" . $this->week, gmdate( "H", plugin_config_get( 'time_day_start' ) ) . "-" . gmdate( "H", plugin_config_get( 'time_day_finish' ) ) );
print_small_button( plugin_page( 'calendar_user_page' ) . "&for_user=" . $this->for_user . "&week=" . $this->week . "&year=" . $this->year, gmdate( "H", plugin_config_get( 'time_day_start' ) ) . "-" . gmdate( "H", plugin_config_get( 'time_day_finish' ) ) );
}
echo '</div>';

echo '<div class="btn-group pull-right">';
if( self::$full_time_is == FALSE ) {
print_small_button( plugin_page( 'calendar_user_page' ) . "&for_user=" . $this->for_user . "&week=" . ($this->week - 1), plugin_lang_get( 'previous_period' ) );
print_small_button( plugin_page( 'calendar_user_page' ) . "&for_user=" . $this->for_user . "&week=" . date( "W", timestamp_previous_week_get( $this->week, $this->year ) ) . "&year=" . date( "Y", timestamp_previous_week_get( $this->week, $this->year ) ), plugin_lang_get( 'previous_period' ) );
print_small_button( plugin_page( 'calendar_user_page' ) . "&for_user=" . $this->for_user . "&week=" . (int)date( "W" ), plugin_lang_get( 'week' ) );
print_small_button( plugin_page( 'calendar_user_page' ) . "&for_user=" . $this->for_user . "&week=" . ($this->week + 1), plugin_lang_get( 'next_period' ) );
print_small_button( plugin_page( 'calendar_user_page' ) . "&for_user=" . $this->for_user . "&week=" . date( "W", timestamp_next_week_get( $this->week, $this->year ) ) . "&year=" . date( "Y", timestamp_next_week_get( $this->week, $this->year ) ), plugin_lang_get( 'next_period' ) );
} else {
print_small_button( plugin_page( 'calendar_user_page' ) . "&for_user=" . $this->for_user . "&week=" . ($this->week - 1) . "&full_time=TRUE", plugin_lang_get( 'previous_period' ) );
print_small_button( plugin_page( 'calendar_user_page' ) . "&for_user=" . $this->for_user . "&week=" . date( "W", timestamp_previous_week_get( $this->week, $this->year ) ) . "&year=" . date( "Y", timestamp_previous_week_get( $this->week, $this->year ) ) . "&full_time=TRUE", plugin_lang_get( 'previous_period' ) );
print_small_button( plugin_page( 'calendar_user_page' ) . "&for_user=" . $this->for_user . "&week=" . (int)date( "W" ) . "&full_time=TRUE", plugin_lang_get( 'week' ) );
print_small_button( plugin_page( 'calendar_user_page' ) . "&for_user=" . $this->for_user . "&week=" . ($this->week + 1) . "&full_time=TRUE", plugin_lang_get( 'next_period' ) );
print_small_button( plugin_page( 'calendar_user_page' ) . "&for_user=" . $this->for_user . "&week=" . date( "W", timestamp_next_week_get( $this->week, $this->year ) ) . "&year=" . date( "Y", timestamp_next_week_get( $this->week, $this->year ) ) . "&full_time=TRUE", plugin_lang_get( 'next_period' ) );
}
echo '</div>';

Expand Down Expand Up @@ -96,6 +98,7 @@ protected function print_menu_bottom() {
# CSRF protection not required here - form does not result in modifications
echo '<input type="hidden" name="page" value="Calendar/calendar_user_page" />';
echo '<input type="hidden" name="week" value="' . $this->week . '" />';
echo '<input type="hidden" name="year" value="' . $this->year . '" />';
echo '<input type="hidden" name="full_time" value="' . (int)self::$full_time_is . '" />';

echo '<label class="inline">' . plugin_lang_get( 'filter_text' ) . '</label>';
Expand Down
17 changes: 9 additions & 8 deletions Calendar/core/classes/ViewWeekSelect.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
class ViewWeekSelect extends ViewWeekCalendar {
private $bug_id;

public function __construct( $p_week, $p_user, $p_is_full_time, $p_days_events, $p_bug_id ) {
parent::__construct( $p_week, $p_user, $p_is_full_time, $p_days_events, plugin_page( 'event_insert' ) . '&bug_id=' . $p_bug_id . htmlspecialchars( form_security_param( 'event_insert' ) ) );
public function __construct( $p_week, $p_user, $p_is_full_time, $p_days_events, $p_bug_id, $p_year ) {
parent::__construct( $p_week, $p_user, $p_is_full_time, $p_days_events, plugin_page( 'event_insert' ) . '&bug_id=' . $p_bug_id . htmlspecialchars( form_security_param( 'event_insert' ) ), $p_year );
$this->bug_id = (int)$p_bug_id;
}

Expand Down Expand Up @@ -45,21 +45,21 @@ protected function print_menu_top() {

echo '<div class="btn-group pull-left">';
if( WeekCalendar::$full_time_is == FALSE ) {
print_small_button( plugin_page( 'event_insert_page' ) . "&for_user=" . $this->for_user . "&week=" . $this->week . "&full_time=TRUE" . '&id=' . $this->bug_id, "0-24" );
print_small_button( plugin_page( 'event_insert_page' ) . "&for_user=" . $this->for_user . "&week=" . $this->week . "&year=" . $this->year . "&full_time=TRUE" . '&id=' . $this->bug_id, "0-24" );
} else {
print_small_button( plugin_page( 'event_insert_page' ) . "&for_user=" . $this->for_user . "&week=" . $this->week . '&id=' . $this->bug_id, gmdate( "H", plugin_config_get( 'time_day_start' ) ) . "-" . gmdate( "H", plugin_config_get( 'time_day_finish' ) ) );
print_small_button( plugin_page( 'event_insert_page' ) . "&for_user=" . $this->for_user . "&week=" . $this->week . "&year=" . $this->year . '&id=' . $this->bug_id, gmdate( "H", plugin_config_get( 'time_day_start' ) ) . "-" . gmdate( "H", plugin_config_get( 'time_day_finish' ) ) );
}
echo '</div>';

echo '<div class="btn-group pull-right">';
if( WeekCalendar::$full_time_is == FALSE ) {
print_small_button( plugin_page( 'event_insert_page' ) . "&for_user=" . $this->for_user . "&week=" . ($this->week - 1) . '&id=' . $this->bug_id, plugin_lang_get( 'previous_period' ) );
print_small_button( plugin_page( 'event_insert_page' ) . "&for_user=" . $this->for_user . "&week=" . date( "W", timestamp_previous_week_get( $this->week, $this->year ) ) . "&year=" . date( "Y", timestamp_previous_week_get( $this->week, $this->year ) ) . '&id=' . $this->bug_id, plugin_lang_get( 'previous_period' ) );
print_small_button( plugin_page( 'event_insert_page' ) . "&for_user=" . $this->for_user . "&week=" . (int)date( "W" ) . '&id=' . $this->bug_id, plugin_lang_get( 'week' ) );
print_small_button( plugin_page( 'event_insert_page' ) . "&for_user=" . $this->for_user . "&week=" . ($this->week + 1) . '&id=' . $this->bug_id, plugin_lang_get( 'next_period' ) );
print_small_button( plugin_page( 'event_insert_page' ) . "&for_user=" . $this->for_user . "&week=" . date( "W", timestamp_next_week_get( $this->week, $this->year ) ) . "&year=" . date( "Y", timestamp_next_week_get( $this->week, $this->year ) ) . '&id=' . $this->bug_id, plugin_lang_get( 'next_period' ) );
} else {
print_small_button( plugin_page( 'event_insert_page' ) . "&for_user=" . $this->for_user . "&week=" . ($this->week - 1) . "&full_time=TRUE" . '&id=' . $this->bug_id, plugin_lang_get( 'previous_period' ) );
print_small_button( plugin_page( 'event_insert_page' ) . "&for_user=" . $this->for_user . "&week=" . date( "W", timestamp_previous_week_get( $this->week, $this->year ) ) . "&year=" . date( "Y", timestamp_previous_week_get( $this->week, $this->year ) ) . "&full_time=TRUE" . '&id=' . $this->bug_id, plugin_lang_get( 'previous_period' ) );
print_small_button( plugin_page( 'event_insert_page' ) . "&for_user=" . $this->for_user . "&week=" . (int)date( "W" ) . "&full_time=TRUE" . '&id=' . $this->bug_id, plugin_lang_get( 'week' ) );
print_small_button( plugin_page( 'event_insert_page' ) . "&for_user=" . $this->for_user . "&week=" . ($this->week + 1) . "&full_time=TRUE" . '&id=' . $this->bug_id, plugin_lang_get( 'next_period' ) );
print_small_button( plugin_page( 'event_insert_page' ) . "&for_user=" . $this->for_user . "&week=" . date( "W", timestamp_next_week_get( $this->week, $this->year ) ) . "&year=" . date( "Y", timestamp_next_week_get( $this->week, $this->year ) ) . "&full_time=TRUE" . '&id=' . $this->bug_id, plugin_lang_get( 'next_period' ) );
}
echo '</div>';

Expand Down Expand Up @@ -88,6 +88,7 @@ protected function print_menu_bottom() {
# CSRF protection not required here - form does not result in modifications
echo '<input type="hidden" name="page" value="Calendar/event_insert_page" />';
echo '<input type="hidden" name="week" value="' . $this->week . '" />';
echo '<input type="hidden" name="year" value="' . $this->year . '" />';
echo '<input type="hidden" name="full_time" value="' . (int)self::$full_time_is . '" />';
echo '<input type="hidden" name="id" value="' . $this->bug_id . '" />';

Expand Down
19 changes: 16 additions & 3 deletions Calendar/pages/calendar_user_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,34 @@
# don't index view issues pages
html_robots_noindex();

$t_current_week = date( "W" );
$t_current_year = date( "Y" );
$t_year_start_of_current_week = date( "Y", strtotime( 'this week' ) );

$f_week = gpc_get_int( "week", date( "W" ) );
if( $t_current_year != $t_year_start_of_current_week ) {
$t_current_year = $t_year_start_of_current_week;
}

$f_week = gpc_get_int( "week", $t_current_week );
$f_year = gpc_get_int( "year", $t_current_year );
$f_is_fulltime = gpc_get_bool( "full_time" );
$f_for_user = gpc_get_int( "for_user", auth_get_current_user_id() );
//$t_access_level_current_user = access_get_project_level();
//$t_access_level_global_current_user = access_get_global_level();

if( strtotime( $f_year . 'W' . str_pad( $f_week, 2, 0, STR_PAD_LEFT ) ) == false ) {
error_parameters( plugin_lang_get( 'date_event' ) );
plugin_error( 'ERROR_RANGE_TIME', ERROR );
}

$t_start_day_of_the_week = plugin_config_get( "startStepDays" );
$t_step_days_count = plugin_config_get( "countStepDays" );
$t_arWeekdaysName = plugin_config_get( "arWeekdaysName" );

$t_days = days_of_number_week( $t_start_day_of_the_week, $t_step_days_count, $t_arWeekdaysName, $f_week );
$t_days = days_of_number_week( $t_start_day_of_the_week, $t_step_days_count, $t_arWeekdaysName, $f_week, $f_year );
$t_days_events = get_days_object( $t_days, helper_get_current_project(), $f_for_user );

$t_calendar_week = new ViewWeekCalendar( $f_week, $f_for_user, $f_is_fulltime, $t_days_events, plugin_page( 'view' ) );
$t_calendar_week = new ViewWeekCalendar( $f_week, $f_for_user, $f_is_fulltime, $t_days_events, plugin_page( 'view' ), $f_year );

$t_calendar_week->print_html();

Expand Down
18 changes: 15 additions & 3 deletions Calendar/pages/event_insert_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,33 @@
# don't index view issues pages
html_robots_noindex();

$t_current_week = date( "W" );
$t_current_year = date( "Y" );
$t_year_start_of_current_week = date( "Y", strtotime( 'this week' ) );

if( $t_current_year != $t_year_start_of_current_week ) {
$t_current_year = $t_year_start_of_current_week;
}

$f_week = gpc_get_int( "week", date( "W" ) );
$f_week = gpc_get_int( "week", $t_current_week );
$f_year = gpc_get_int( "year", $t_current_year );
$f_is_fulltime = gpc_get_bool( "full_time" );
$f_for_user = gpc_get_int( "for_user", auth_get_current_user_id() );

if( strtotime( $f_year . 'W' . str_pad( $f_week, 2, 0, STR_PAD_LEFT ) ) == false ) {
error_parameters( plugin_lang_get( 'date_event' ) );
plugin_error( 'ERROR_RANGE_TIME', ERROR );
}

$t_start_day_of_the_week = plugin_config_get( "startStepDays" );
$t_step_days_count = plugin_config_get( "countStepDays" );
$t_arWeekdaysName = plugin_config_get( "arWeekdaysName" );

$t_excluded_events = get_events_id_from_bug_id( $f_bug_id );
$t_days = days_of_number_week( $t_start_day_of_the_week, $t_step_days_count, $t_arWeekdaysName, $f_week );
$t_days = days_of_number_week( $t_start_day_of_the_week, $t_step_days_count, $t_arWeekdaysName, $f_week, $f_year );
$t_days_events = get_days_object( $t_days, helper_get_current_project(), $f_for_user, $t_excluded_events );

$t_calendar_week = new ViewWeekSelect( $f_week, $f_for_user, $f_is_fulltime, $t_days_events, $f_bug_id );
$t_calendar_week = new ViewWeekSelect( $f_week, $f_for_user, $f_is_fulltime, $t_days_events, $f_bug_id, $f_year );

$t_calendar_week->print_html();

Expand Down

0 comments on commit b26236c

Please sign in to comment.