747699a3d283c59beca204d245ddd774424a1eaf
[phancap.git] / www / setup.php
1 <?php
2 namespace phancap;
3 /**
4  * Check if everything is setup
5  */
6 header('HTTP/1.0 500 Internal Server Error');
7
8 if (file_exists(__DIR__ . '/../src/phancap/Autoloader.php')) {
9     include_once __DIR__ . '/../src/phancap/Autoloader.php';
10     Autoloader::register();
11 } else {
12     include_once 'phancap/Autoloader.php';
13 }
14
15 $messages = array();
16
17 $config = new Config();
18 try {
19     $config->load();
20     $messages[][] = array('ok', 'Configuration check ok');
21 } catch (\Exception $e) {
22     $messages[][] = array('err', $e->getMessage());
23 }
24
25 $adapter = array(
26     'Cutycapt'
27 );
28 foreach ($adapter as $classpart) {
29     $class = '\\phancap\\Adapter_' . $classpart;
30     $adapter = new $class();
31     $adapter->setConfig($config);
32     $errors = $adapter->isAvailable();
33     if ($errors === true) {
34         $messages[][] = array(
35             'ok', 'Adapter ' . $classpart . ' is available'
36         );
37     } else {
38         foreach ($errors as $msg) {
39             $messages['Adapter: '. $classpart][] = array('err', $msg);
40         }
41     }
42 }
43
44 header('HTTP/1.0 200 OK');
45
46 $out = <<<HTM
47 <?xml version="1.0" encoding="utf-8"?>
48 <html>
49  <head>
50   <title>phancap setup check</title>
51   <style type="text/css">
52     li.ok:before {
53         content: '✔';
54         color: green;
55         padding: 0 0.5ex;
56         margin-right: 1ex;
57     }
58     li.err:before {
59         content: "✘";
60         color: white;
61         background-color: red;
62         padding: 0 0.5ex;
63         margin-right: 0.5ex;
64     }
65   </style>
66  </head>
67  <body>
68   <h1>phancap setup check</h1>
69 <ul>
70 HTM;
71 foreach ($messages as $key => $messages) {
72     if (!is_numeric($key)) {
73         $out .= '<li>' . htmlspecialchars($key)
74             . '<ul>';
75     }
76     foreach ($messages as $data) {
77         list($state, $message) = $data;
78         $out .= '<li class="' . $state . '">';
79         $out .= htmlspecialchars($message);
80         $out .= '</li>' . "\n";
81     }
82     if (!is_numeric($key)) {
83         $out .= '</ul></li>' . "\n";
84     }
85 }
86 $out .= <<<HTM
87   </ul>
88   <p>
89    <a href="./">back</a> to the index
90   </p>
91  </body>
92 </html>
93 HTM;
94 echo $out;
95 ?>