Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- elseif ($page_action == 'add_confirm') {
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- if ($_POST["toggleSwitch"] == 0) { // When checkbox unchecked
- // Get the current year
- $currentYear = date("Y");
- // Get all the holidays in the file
- $allHolidays = handleFileUpload("holiday_list");
- // If no error exists
- if(!array_key_exists("ERROR", $allHolidays)) {
- // Fetch existing holidays in the db
- $existingHolidayList = array();
- $query = $database->query("SELECT holiday_date FROM " . TABLE_HOLIDAYS);
- while($existingHoliday = $database->fetch_array($query)) {
- $existingHolidayList[] = $existingHoliday["holiday_date"];
- }
- foreach ($allHolidays["VEVENT"] as $holiday) {
- $startDate = $holiday["DTSTART"];
- $holiday_year = date("Y", strtotime($startDate));
- $holiday_month = date("m", strtotime($startDate));
- $holiday_day = date("d", strtotime($startDate));
- // If the holiday year in the file is same or greater than the current year
- if($holiday_year >= $currentYear) {
- $holidayDate = $holiday_year . '-' . $holiday_month . '-' . $holiday_day;
- // Check if the date is already present in the database
- if(!in_array($holidayDate, $existingHolidayList)) {
- $database->query("INSERT INTO " . TABLE_HOLIDAYS . " (holiday_date, holiday_year) VALUES ('" . $holidayDate . "', '" . $holiday_year . "')");
- }
- }
- }
- // Display Success message
- $message = "Holidays Successfully Added";
- $msgClass = "mainSuccess";
- }
- else {
- // Display Error message
- $message = $allHolidays["ERROR"]["MSG"];
- $msgClass = "mainError";
- }
- }
- elseif ($_POST["toggleSwitch"] == 1) { // When checkbox checked
- $date = $_POST["holidayPicker"];
- // ToDo Check to add upcoming holidays only
- if(!empty($date)) {
- $holiday_year = date("Y", strtotime($date));
- $holiday_month = date("m", strtotime($date));
- $holiday_day = date("d", strtotime($date));
- // Check if the entered date is a valid date
- if(checkdate($holiday_month, $holiday_day, $holiday_year)) {
- $holidayDate = $holiday_year . '-' . $holiday_month . '-' . $holiday_day;
- $existingHolidayList = array();
- $query = $database->query("SELECT holiday_date FROM " . TABLE_HOLIDAYS);
- while ($existingHoliday = $database->fetch_array($query)) {
- $existingHolidayList[] = $existingHoliday["holiday_date"];
- }
- if (!in_array($holidayDate, $existingHolidayList)) {
- $database->query("INSERT INTO " . TABLE_HOLIDAYS . " (holiday_date, holiday_year) VALUES ('" . $holidayDate . "', '" . $holiday_year . "')");
- // Display Success message
- $message = "Holiday Successfully Added";
- $msgClass = "mainSuccess";
- } else {
- // Display Error message
- $message = "Holiday already exists";
- $msgClass = "mainError";
- }
- }
- else {
- // Display Error message
- $message = "Invalid date or the date has passed";
- $msgClass = "mainError";
- }
- }
- else {
- // Display Error message
- $message = "Select a date";
- $msgClass = "mainError";
- }
- }
- }
- $action = '';
- }
Add Comment
Please, Sign In to add comment