summaryrefslogtreecommitdiff
path: root/includes/pages/admin_settings.php
blob: ebee1305a5592d63a4e67d16639f9a4b4a5810ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php

function admin_settings_title() {
  return _("Settings");
}

function admin_settings() {
  $event_name = null;
  $event_welcome_msg = null;
  $buildup_start_date = null;
  $event_start_date = null;
  $event_end_date = null;
  $teardown_end_date = null;
  
  $settings_source = Settings();
  if ($settings_source === false)
    engelsystem_error('Unable to load settings.');
  if ($settings_source != null) {
    $event_name = $settings_source['event_name'];
    $buildup_start_date = $settings_source['buildup_start_date'];
    $event_start_date = $settings_source['event_start_date'];
    $event_end_date = $settings_source['event_end_date'];
    $teardown_end_date = $settings_source['teardown_end_date'];
    $event_welcome_msg = $settings_source['event_welcome_msg'];
  }
  
  if (isset($_REQUEST['submit'])) {
    $ok = true;
    
    if (isset($_REQUEST['event_name']))
      $event_name = strip_request_item('event_name');
    if ($event_name == '')
      $event_name = null;
    
    if (isset($_REQUEST['event_welcome_msg']))
      $event_welcome_msg = strip_request_item_nl('event_welcome_msg');
    if ($event_welcome_msg == '')
      $event_welcome_msg = null;
    
    $result = check_request_date('buildup_start_date', _("Please enter buildup start date."), true);
    $buildup_start_date = $result->getValue();
    $ok &= $result->isOk();
    
    $result = check_request_date('event_start_date', _("Please enter event start date."), true);
    $event_start_date = $result->getValue();
    $ok &= $result->isOk();
    
    $result = check_request_date('event_end_date', _("Please enter event end date."), true);
    $event_end_date = $result->getValue();
    $ok &= $result->isOk();
    
    $result = check_request_date('teardown_end_date', _("Please enter teardown end date."), true);
    $teardown_end_date = $result->getValue();
    $ok &= $result->isOk();
    
    if ($ok) {
      $result = Settings_update($event_name, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date, $event_welcome_msg);
      
      if ($result === false)
        engelsystem_error("Unable to update settings.");
      
      success(_("Settings saved."));
      redirect(page_link_to('admin_settings'));
    }
  }
  
  return page_with_title(admin_settings_title(), [
      msg(),
      form([
          div('row', [
              div('col-md-6', [
                  form_text('event_name', _("Event Name"), $event_name),
                  form_info('', _("Event Name is shown on the start page.")),
                  form_textarea('event_welcome_msg', _("Event Welcome Message"), $event_welcome_msg),
                  form_info('', _("Welcome message is shown after successful registration. You can use markdown.")) 
              ]),
              div('col-md-3', [
                  form_date('buildup_start_date', _("Buildup date"), $buildup_start_date),
                  form_date('event_start_date', _("Event start date"), $event_start_date) 
              ]),
              div('col-md-3', [
                  form_date('teardown_end_date', _("Teardown end date"), $teardown_end_date),
                  form_date('event_end_date', _("Event end date"), $event_end_date) 
              ]) 
          ]),
          div('row', [
              div('col-md-6', [
                  form_submit('submit', _("Save")) 
              ]) 
          ]) 
      ]) 
  ]);
}
?>