Add data protection statement
[infodrom.org/infocon.infodrom.org] / class / teachings.class.php
1 <?php
2
3 define('TEACHINGS', $_SERVER['DOCUMENT_ROOT'] . '/teachings.txt');
4
5 class Teachings {
6   private static $instance = false;
7   private $list = array();
8
9   public static function instance()
10   {
11     if (self::$instance === false)
12       self::$instance = new Teachings(TEACHINGS);
13
14     return self::$instance;
15   }
16
17   private function __construct($path)
18   {
19     $this->import($path);
20   }
21
22   private function import($path)
23   {
24     if (($f = fopen($path, 'r')) === false) return;
25
26     while ($line = fgets($f)) {
27       $a = explode('|', chop($line));
28       $this->list[] = new Storage(array('start' => $a[0],
29                                         'end' => $a[1],
30                                         'location' => $a[2],
31                                         'title' => $a[3],
32                                         'url' => $a[4]));
33     }
34
35     fclose($f);
36   }
37
38   public function getCurrent()
39   {
40   }
41
42   public function getList()
43   {
44     $html = '';
45     foreach ($this->list as $row) {
46       if (strpos($row->location, 'Linuxhotel GmbH') === false) continue;
47
48       $dstart = explode('-', $row->start);
49       $dend = explode('-', $row->end);
50
51       if ($dstart[1] == $dend[1])
52         $date = sprintf('%d.-%d.%d.%d', $dstart[2], $dend[2], $dstart[1], $dstart[0]);
53       else
54         $date = sprintf('%d.%d.-%d.%d.%d', $dstart[2], $dstart[1], $dend[2], $dstart[1], $dstart[0]);
55
56       $link = strlen($row->url) ? sprintf('<a href="%s">Details / Buchen</a>', $row->url) : '';
57       $html .= sprintf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>',
58                        $date,
59                        str_replace('\\', '', $row->title),
60                        $link);
61     }
62
63     if (strlen($html)) {
64       $html = '<table class="teachings" width="100%">'
65         . '<thead>'
66         . '<tr>'
67         . '<th width="20%">Datum</th>'
68         . '<th width="60%" align="left">Beschreibung</th>'
69         . '<th width="20%">Link</th>'
70         . '</tr>'
71         . '</thead>'
72         . '<tbody>'
73         . $html
74         . '</tbody>'
75         . '</table>';
76     }
77
78     return $html;
79   }
80 }
81