1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
$di->set('EventController', function() use ($di) {
|
4
|
|
|
$controller = new \Anax\Events\EventController();
|
5
|
|
|
$controller->setDI($di);
|
6
|
|
|
return $controller;
|
7
|
|
|
});
|
8
|
|
|
|
9
|
|
|
$di->setShared('db', function() {
|
10
|
|
|
$db = new \Mos\Database\CDatabaseBasic();
|
11
|
|
|
$db->setOptions(require ANAX_APP_PATH . 'config/events_sqlite.php');
|
12
|
|
|
$db->connect();
|
13
|
|
|
return $db;
|
14
|
|
|
});
|
15
|
|
|
|
16
|
|
|
$app->router->add('calendar-create-database', function() use ($app) {
|
17
|
|
|
|
18
|
|
|
$app->db->dropTableIfExists('event')->execute();
|
19
|
|
|
|
20
|
|
|
$app->db->createTable(
|
21
|
|
|
'event',
|
22
|
|
|
[
|
23
|
|
|
'id' => ['integer', 'primary key', 'not null', 'auto_increment'],
|
24
|
|
|
'title' => ['varchar(80)'],
|
25
|
|
|
'name' => ['varchar(80)'],
|
26
|
|
|
'content' => ['text'],
|
27
|
|
|
'showdate' => ['datetime'],
|
28
|
|
|
'startdate' => ['datetime'],
|
29
|
|
|
'stopdate' => ['datetime'],
|
30
|
|
|
'created' => ['datetime'],
|
31
|
|
|
'updated' => ['datetime'],
|
32
|
|
|
'status' => ['datetime'],
|
33
|
|
|
]
|
34
|
|
|
)->execute();
|
35
|
|
|
|
36
|
|
|
$url = $app->url->create('calendar');
|
37
|
|
|
$app->response->redirect($url);
|
38
|
|
|
});
|
39
|
|
|
|
40
|
|
|
$app->router->add('add-event', function() use ($app) {
|
41
|
|
|
$app->theme->setTitle("Add event");
|
42
|
|
|
|
43
|
|
|
$form = new \Mos\HTMLForm\CForm();
|
44
|
|
|
|
45
|
|
|
$form = $form->create([], [
|
46
|
|
|
'title' => [
|
47
|
|
|
'type' => 'text',
|
48
|
|
|
'label' => 'Title',
|
49
|
|
|
'required' => true,
|
50
|
|
|
'validation' => ['not_empty'],
|
51
|
|
|
],
|
52
|
|
|
'name' => [
|
53
|
|
|
'type' => 'text',
|
54
|
|
|
'label' => 'Name',
|
55
|
|
|
'required' => true,
|
56
|
|
|
'validation' => ['not_empty'],
|
57
|
|
|
],
|
58
|
|
|
'content' => [
|
59
|
|
|
'type' => 'textarea',
|
60
|
|
|
'label' => 'Content',
|
61
|
|
|
'required' => true,
|
62
|
|
|
'validation' => ['not_empty'],
|
63
|
|
|
],
|
64
|
|
|
'submit' => [
|
65
|
|
|
'type' => 'submit',
|
66
|
|
|
'label' => 'Add',
|
67
|
|
|
'callback' => function($form) {
|
68
|
|
|
$form->saveInSession = true;
|
69
|
|
|
return true;
|
70
|
|
|
}
|
71
|
|
|
],
|
72
|
|
|
]);
|
73
|
|
|
|
74
|
|
|
// Check the status of the form
|
75
|
|
|
$status = $form->check();
|
76
|
|
|
|
77
|
|
View Code Duplication |
if ($status === true) {
|
78
|
|
|
|
79
|
|
|
$app->dispatcher->forward([
|
80
|
|
|
'controller' => 'calendar',
|
81
|
|
|
'action' => 'add',
|
82
|
|
|
]);
|
83
|
|
|
|
84
|
|
|
} else if ($status === false) {
|
85
|
|
|
|
86
|
|
|
var_dump('Check method returned false');
|
|
|
|
|
87
|
|
|
die;
|
88
|
|
|
}
|
89
|
|
|
|
90
|
|
|
|
91
|
|
|
$app->views->add('me/page', [
|
92
|
|
|
'title' => 'Add event',
|
93
|
|
|
'content' => $form->getHTML()
|
94
|
|
|
]);
|
95
|
|
|
});
|
96
|
|
|
|
97
|
|
|
$app->router->add('calendar', function() use ($app) {
|
98
|
|
|
|
99
|
|
|
$app->theme->setTitle("Welcome to Anax Calendar");
|
100
|
|
|
$app->views->add('calendar/index');
|
101
|
|
|
|
102
|
|
|
$date = $app->request->getGet('date');
|
103
|
|
|
|
104
|
|
|
$app->dispatcher->forward([
|
105
|
|
|
'controller' => 'event',
|
106
|
|
|
'action' => 'view',
|
107
|
|
|
'params' => ['date' => $date]
|
108
|
|
|
]);
|
109
|
|
|
|
110
|
|
|
});
|
111
|
|
|
|