<?php

$DIS_Application = "Administration";
$year = value_from_POST_GET('year', strftime("%Y"));
$week = value_from_POST_GET('week');
$weeks = value_from_POST_GET('weeks');
// Administration
$admin = value_from_POST_GET('admin');
$is_admin = isset($admin) && isValidAdminPassword($admin);
if ($is_admin) {
    require INC_DIR . "reporting_lib.inc";
    $today_week = currentWeekNumber();
    $today_year = currentYear();
    $DIS_CurrentWeek = $today_week;
    $DIS_Year = $year;
    if (!isset($task) && isset($_POST['task'])) {
        $task = $_POST['task'];
    }
    $task_nothing = "nothing";
    $task_refresh = "refresh";
    $task_delete = "delete";
    $task_switch_lock = "switch-lock";
    $task_reportinglistcreation = "CreateReportingList";
    $task_send_email = "SendEmail";
    $task_send_reminder = "SendReminder";
    if (!isset($task)) {
        $task = $task_nothing;
    }
    switch ($task) {
        case $task_send_email:
            $cmd = sendReportsMailScript() . " " . $weeks[0] . " new ";
//  year => [year]
//          [weeks] => [
//							[week] => [file]
//							          [first_day]
//							          [last_day]
//							          [last_modified]
//							          [status]
//							          [style]
//							          [nota]
//
if (isset($year)) {
    $reporting_dirs = array($year => yearDirname($year));
} else {
    $reporting_dirs = listOfKnownYear();
}
$current_weeknumber = currentWeekNumber();
$current_year = currentYear();
while (list($k_year, $v_dirpath) = each($reporting_dirs)) {
    if (!isset($selected_year)) {
        $selected_year = $k_year;
    }
    if ($k_year == $selected_year) {
        $TMP_Year = array();
        $TMP_Year['year'] = $k_year;
        $week_files = listOfWeekFilesInDirByWeekNumber($v_dirpath);
        if (count($week_files) > 0) {
            $TMP_Weeks = array();
            while (list($k_week, $v_file) = each($week_files)) {
                $TMP_ThisWeek = array();
                // Data
                $TMP_ThisWeek['file'] = $v_file;
                        $DIS_EditReportingText .= "       <li>...</li>\n";
                        $DIS_EditReportingText .= "    </ul>\n";
                    }
                } else {
                    $DIS_EditReportingText .= "<li>...</li>\n";
                }
                $DIS_EditReportingText .= "</ul>\n\n";
            }
        }
    }
} else {
    // Checking for username //
    if ($data_filled && !isset($username)) {
        $DIS_PostWarning = "You forgot to select your username, this is required";
    }
    $users = $GLOBALS['reporting']['users'];
    @($DIS_PostUsername_HTML_SELECT = userList_HTML_SELECT('username', $users, 'Select your username', $username));
    //		// Year
    //		$DIS_PostYear_HTML_3_RADIO = number_HTML_3_RADIO ('year', $year);
    //
    //		// Week
    //		$DIS_PostWeek_HTML_3_RADIO = number_HTML_3_RADIO ('week', $week);
    $today = currentDay();
    $firstday_of_week = firstDayOfCurrentWeek();
    $lastday_of_week = lastDayOfCurrentWeek();
    $DIS_PostCurrent_Week_text = "week <strong>#" . currentWeekNumber() . "</strong> [" . $firstday_of_week . " - " . $lastday_of_week . "]";
    //$DIS_PostWeek_HTML_RADIO_SELECT = week_HTML_RADIO_SELECT ($year, $week, 'week', 'postreportingForm');
    $DIS_PostYearWeek_HTML_RADIO_SELECT = year_week_HTML_RADIO_SELECT($year, $week, 'year', 'week', 'postreportingForm');
    $categories = $GLOBALS['reporting']["categories"];
    $DIS_PostCategories_HTML_CHECK_LIST = categories_HTML_CHECK_LIST($categories, 'cat_sel[]');
}