Code Duplication    Length = 15-16 lines in 2 locations

main/inc/lib/agenda.lib.php 2 locations

@@ 2901-2916 (lines=16) @@
2898
            $sql = "SELECT * FROM ".$tbl_global_agenda." WHERE MONTH(start_date) = ".$month." AND YEAR(start_date) = ".$year."  AND access_url_id = $current_access_url_id ORDER BY start_date ASC";
2899
        }
2900
        // 2. creating the SQL statement for getting the personal agenda items in WEEK view
2901
        if ($type == "week_view") { // we are in week view
2902
            $start_end_day_of_week = self::calculate_start_end_of_week($week, $year);
2903
            $start_day = $start_end_day_of_week['start']['day'];
2904
            $start_month = $start_end_day_of_week['start']['month'];
2905
            $start_year = $start_end_day_of_week['start']['year'];
2906
            $end_day = $start_end_day_of_week['end']['day'];
2907
            $end_month = $start_end_day_of_week['end']['month'];
2908
            $end_year = $start_end_day_of_week['end']['year'];
2909
            // in sql statements you have to use year-month-day for date calculations
2910
            $start_filter = $start_year."-".$start_month."-".$start_day." 00:00:00";
2911
            $start_filter = api_get_utc_datetime($start_filter);
2912
2913
            $end_filter = $end_year."-".$end_month."-".$end_day." 23:59:59";
2914
            $end_filter = api_get_utc_datetime($end_filter);
2915
            $sql = " SELECT * FROM ".$tbl_global_agenda." WHERE start_date>='".$start_filter."' AND start_date<='".$end_filter."' AND  access_url_id = $current_access_url_id ";
2916
        }
2917
        // 3. creating the SQL statement for getting the personal agenda items in DAY view
2918
        if ($type == "day_view") { // we are in day view
2919
            // we could use mysql date() function but this is only available from 4.1 and higher
@@ 3026-3040 (lines=15) @@
3023
3024
        // 2. creating the SQL statement for getting the personal agenda items in WEEK view
3025
        // we are in week view
3026
        if ($type == "week_view") {
3027
            $start_end_day_of_week = self::calculate_start_end_of_week($week, $year);
3028
            $start_day = $start_end_day_of_week['start']['day'];
3029
            $start_month = $start_end_day_of_week['start']['month'];
3030
            $start_year = $start_end_day_of_week['start']['year'];
3031
            $end_day = $start_end_day_of_week['end']['day'];
3032
            $end_month = $start_end_day_of_week['end']['month'];
3033
            $end_year = $start_end_day_of_week['end']['year'];
3034
            // in sql statements you have to use year-month-day for date calculations
3035
            $start_filter = $start_year."-".$start_month."-".$start_day." 00:00:00";
3036
            $start_filter  = api_get_utc_datetime($start_filter);
3037
            $end_filter = $end_year."-".$end_month."-".$end_day." 23:59:59";
3038
            $end_filter  = api_get_utc_datetime($end_filter);
3039
            $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' AND date>='".$start_filter."' AND date<='".$end_filter."'";
3040
        }
3041
        // 3. creating the SQL statement for getting the personal agenda items in DAY view
3042
        if ($type == "day_view") {
3043
            // we are in day view