<?php
/**
 * The file contains a listing of all the current WebCalendar config settings
 * and their default values.
 */
$webcalConfig = [
  'ADD_LINK_IN_VIEWS' => 'N',
  'ADMIN_OVERRIDE_UAC' => 'Y',
  'ALLOW_ATTACH' => 'N',
  'ALLOW_ATTACH_ANY' => 'N',
  'ALLOW_ATTACH_PART' => 'N',
  'ALLOW_COLOR_CUSTOMIZATION' => 'Y',
  'ALLOW_COMMENTS' => 'N',
  'ALLOW_COMMENTS_ANY' => 'N',
  'ALLOW_COMMENTS_PART' => 'N',
  'ALLOW_CONFLICT_OVERRIDE' => 'Y',
  'ALLOW_CONFLICTS' => 'N',
  'ALLOW_EXTERNAL_HEADER' => 'N',
  'ALLOW_EXTERNAL_USERS' => 'N',
  'ALLOW_HTML_DESCRIPTION' => 'Y',
  'ALLOW_SELF_REGISTRATION' => 'N',
  'ALLOW_USER_HEADER' => 'N',
  'ALLOW_USER_THEMES' => 'Y',
  'ALLOW_VIEW_OTHER' => 'Y',
  'APPLICATION_NAME' => 'WebCalendar',
  'APPROVE_ASSISTANT_EVENT' => 'Y',
  'AUTO_REFRESH' => 'N',
  'AUTO_REFRESH_TIME' => '0',
  'BGCOLOR' => '#ffffff',
  'BGIMAGE' => '',
  'BGREPEAT' => 'repeat fixed center',
  'BOLD_DAYS_IN_YEAR' => 'Y',
  'CAPTIONS' => '#b04040',
  'CATEGORIES_ENABLED' => 'Y',
  'CELLBG' => '#c0c0c0',
  'CONFLICT_REPEAT_MONTHS' => '6',
  'CSRF_PROTECTION' => 'Y',
  'CSP' => 'none',
  'CUSTOM_HEADER' => 'N',
  'CUSTOM_SCRIPT' => 'N',
  'CUSTOM_TRAILER' => 'N',
  'DATE_FORMAT' => 'LANGUAGE_DEFINED',
  'DATE_FORMAT_MD' => 'LANGUAGE_DEFINED',
  'DATE_FORMAT_MY' => 'LANGUAGE_DEFINED',
  'DATE_FORMAT_TASK' => 'LANGUAGE_DEFINED',
  'DEMO_MODE' => 'N',
  'DISABLE_ACCESS_FIELD' => 'N',
  'DISABLE_CROSSDAY_EVENTS' => 'N',
  'DISABLE_LOCATION_FIELD' => 'N',
  'DISABLE_PARTICIPANTS_FIELD' => 'N',
  'DISABLE_POPUPS' => 'N',
  'DISABLE_PRIORITY_FIELD' => 'N',
  'DISABLE_REMINDER_FIELD' => 'N',
  'DISABLE_REPEATING_FIELD' => 'N',
  'DISABLE_URL_FIELD' => 'Y',
  'DISPLAY_ALL_DAYS_IN_MONTH' => 'N',
  'DISPLAY_CREATED_BYPROXY' => 'Y',
  'DISPLAY_DESC_PRINT_DAY' => 'Y',
  'DISPLAY_END_TIMES' => 'N',
  'DISPLAY_LOCATION' => 'N',
  'DISPLAY_LONG_DAYS' => 'N',
  'DISPLAY_MINUTES' => 'N',
  'DISPLAY_MOON_PHASES' => 'N',
  'DISPLAY_SM_MONTH' => 'Y',
  'DISPLAY_TASKS' => 'N',
  'DISPLAY_TASKS_IN_GRID' => 'N',
  'DISPLAY_UNAPPROVED' => 'Y',
  'DISPLAY_WEEKENDS' => 'Y',
  'DISPLAY_WEEKNUMBER' => 'Y',
  'EMAIL_ASSISTANT_EVENTS' => 'Y',
  'EMAIL_EVENT_ADDED' => 'Y',
  'EMAIL_EVENT_CREATE' => 'N',
  'EMAIL_EVENT_DELETED' => 'Y',
  'EMAIL_EVENT_REJECTED' => 'Y',
  'EMAIL_EVENT_UPDATED' => 'Y',
  'EMAIL_FALLBACK_FROM' => 'youremailhere',
  'EMAIL_HTML' => 'N',
  'EMAIL_MAILER' => 'mail',
  'EMAIL_REMINDER' => 'Y',
  'ENABLE_CAPTCHA' => 'N',
  'ENABLE_GRADIENTS' => 'N',
  'ENABLE_ICON_UPLOADS' => 'N',
  'ENTRY_SLOTS' => '144',
  'EXTERNAL_NOTIFICATIONS' => 'N',
  'EXTERNAL_REMINDERS' => 'N',
  'FONTS' => 'Arial, Helvetica, sans-serif',
  'FREEBUSY_ENABLED' => 'N',
  'GENERAL_USE_GMT' => 'Y',
  'GROUPS_ENABLED' => 'N',
  'H2COLOR' => '#000000',
  'HASEVENTSBG' => '#ffff30',
  'IMPORT_CATEGORIES' => 'Y',
  'LANGUAGE' => 'none',
  'LIMIT_APPTS' => 'N',
  'LIMIT_APPTS_NUMBER' => '6',
  'LIMIT_DESCRIPTION_SIZE' => 'N',
  'MENU_DATE_TOP' => 'Y',
  'MENU_ENABLED' => 'Y',
  'MENU_THEME' => 'default',
  'MYEVENTS' => '#006000',
  'NONUSER_AT_TOP' => 'Y',
  'NONUSER_ENABLED' => 'Y',
  'OTHERMONTHBG' => '#d0d0d0',
  'OVERRIDE_PUBLIC' => 'N',
  'OVERRIDE_PUBLIC_TEXT' => 'Not available',
  'PARTICIPANTS_IN_POPUP' => 'N',
  'PLUGINS_ENABLED' => 'N',
  'POPUP_BG' => '#ffffff',
  'POPUP_FG' => '#000000',
  'PUBLIC_ACCESS' => 'N',
  'PUBLIC_ACCESS_ADD_NEEDS_APPROVAL' => 'N',
  'PUBLIC_ACCESS_CAN_ADD' => 'N',
  'PUBLIC_ACCESS_DEFAULT_SELECTED' => 'N',
  'PUBLIC_ACCESS_DEFAULT_VISIBLE' => 'N',
  'PUBLIC_ACCESS_OTHERS' => 'Y',
  'PUBLIC_ACCESS_VIEW_PART' => 'N',
  'PUBLISH_ENABLED' => 'Y',
  'PULLDOWN_WEEKNUMBER' => 'N',
  'REMEMBER_LAST_LOGIN' => 'N',
  'REMINDER_DEFAULT' => 'N',
  'REMINDER_OFFSET' => '240',
  'REMINDER_WITH_DATE' => 'N',
  'REMOTES_ENABLED' => 'N',
  'REPORTS_ENABLED' => 'N',
  'REQUIRE_APPROVALS' => 'Y',
  'RSS_ENABLED' => 'N',
  'SELF_REGISTRATION_BLACKLIST' => 'N',
  'SELF_REGISTRATION_FULL' => 'Y',
  'SEND_EMAIL' => 'N',
  'SERVER_TIMEZONE' => 'America/New_York',
  'SITE_EXTRAS_IN_POPUP' => 'N',
  'SMTP_AUTH' => 'N',
  'SMTP_STARTTLS' => 'Y',
  'SMTP_HOST' => 'localhost',
  'SMTP_PASSWORD' => '',
  'SMTP_PORT' => '25',
  'SMTP_USERNAME' => '',
  'STARTVIEW' => 'month.php',
  'SUMMARY_LENGTH' => '80',
  'TABLEBG' => '#000000',
  'TEXTCOLOR' => '#000000',
  'THBG' => '#ffffff',
  'THFG' => '#000000',
  'TIME_FORMAT' => '12',
  'TIME_SLOTS' => '24',
  'TIME_SPACER' => '&raquo;&nbsp;',
  'TIMED_EVT_LEN' => 'D',
  'TIMEZONE' => 'America/New_York',
  'TODAYCELLBG' => '#ffff30',
  'UAC_ENABLED' => 'N',
  'USER_PUBLISH_ENABLED' => 'Y',
  'USER_PUBLISH_RW_ENABLED' => 'Y',
  'USER_RSS_ENABLED' => 'N',
  'USER_SEES_ONLY_HIS_GROUPS' => 'Y',
  'USER_SORT_ORDER' => 'cal_lastname, cal_firstname',
  'WEBCAL_PROGRAM_VERSION' => 'v1.9.19',
  'WEEK_START' => '0',
  'WEEKEND_START' => '6',
  'WEEKENDBG' => '#d0d0d0',
  'WEEKNUMBER' => '#f06030',
  'WORK_DAY_END_HOUR' => '17',
  'WORK_DAY_START_HOUR' => '8'
];

/**
 * db_load_config (needs description)
 *
 * This function is defined here because admin.php calls it during startup.
 * Load default configuration values into the webcal_config table but only
 * if values are not already there.
 */
function db_load_config() {
  global $webcalConfig;

  $sql = 'INSERT INTO webcal_config ( cal_setting, cal_value ) VALUES ( ?, ? )';

  foreach ($webcalConfig as $key => $val) {
    $res = dbi_execute( 'SELECT cal_value FROM webcal_config
      WHERE cal_setting = ?', [$key], false, false );
    if( ! $res ) {
      dbi_execute( $sql, [$key, $val] );
    }
    else { // SQLite returns $res always.
      $row = dbi_fetch_row( $res );
      if( ! isset( $row[0] ) )
        dbi_execute( $sql, [$key, $val] );

      dbi_free_result( $res );
    }
  }
}

?>
