]> dev.renevier.net Git - syp.git/blob - inc/templates_wizard.php
f556991a67eccf75a927e010bbb1d2dc585c5d19
[syp.git] / inc / templates_wizard.php
1 <?php
2 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
3    license. */
4 ?>
5 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
6        "http://www.w3.org/TR/html4/loose.dtd">  
7 <html>
8 <head>
9       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
10       <link rel="stylesheet" href="./media/common.css" type="text/css" />
11       <title><?php ptrans ('SYP wizard')?></title>
12       <script type="text/javascript">
13       function init () {
14         if (document.getElementById('password')) { 
15             document.getElementById('password').focus();
16             document.getElementById('password').select();
17         }
18       </script>
19 </head>
20 <body onload="init()">
21
22 <?php
23     function leave () {
24         exit ("\n</body></html>");
25     }
26     function wiz_success ($message) {
27         printf ("<p class=\"success center\">%s</p>", $message);
28     }
29     function wiz_error ($message) {
30         printf ("<p class=\"error center\">%s</p>", $message);
31         leave ();
32     }
33     function wiz_warn ($message) {
34         printf ("<p class=\"warn center\">%s</p>", $message);
35     }
36
37     if (version_compare (PHP_VERSION, '5.0.0', '<')) {
38         wiz_error (trans ("You need at least PHP version 5"));
39     }
40
41     require_once ("./inc/settings.php");
42     require_once ("./inc/db/mysql.php");
43
44     try {
45         $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
46     } catch (Exception $e) {
47         switch ($e->getMessage ()) {
48             case anydbConnection::err_driver_unavailable:
49                 wiz_error ($connection->getdbname() . ': ' . trans ('not supported'));
50             case anydbConnection::err_connection:
51                 wiz_error (trans ('Could not connect to database.'));
52             case anydbConnection::err_unknown_database:
53                 wiz_error (trans ('Database does not exist.'));
54             default:
55                 wiz_error (trans ('Unknown error when connecting to database.'));
56         }
57     }
58     try {
59         $users_table_exists = $connection->users_table_exists ();
60     } catch(Exception $e) {
61         wiz_error (trans ('Unknown error when checking user table.'));
62     }
63
64     if ($users_table_exists) {
65         wiz_success (trans ('Found user table.'));
66     } else {
67         if (isset($_POST ["password"])) {
68             try {
69                 $connection->create_users_table (true);
70             } catch (Exception $e) {
71                 wiz_error (trans ('Error when creating user table.'));
72             }
73             wiz_success (trans ('User table created.'));
74             try {
75                 $connection->setpwd ("admin", $_POST ["password"]);
76             } catch (Exception $e) {
77                 wiz_error (trans ('Error when initializing password.'));
78             }
79             wiz_success (trans ('Admin password initialized.'));
80
81         } else {
82             print ('<form class="center" method="post" action="">
83                     <label for="password">' . trans ("choose admin password") . '</label>
84                     <input id="password" name="password" type="password">
85                     <input type="submit">
86                  </form>');
87             leave ();
88         }
89
90     }
91
92     try {
93         $items_table_exists = $connection->items_table_exists ();
94     } catch (Exception $e) {
95         wiz_error (trans ('Unknown error when checking data table.'));
96     }
97     if ($items_table_exists) {
98         wiz_success (trans ('Found data table.'));
99     } else {
100         try {
101             $connection->create_items_table (true);
102         } catch (Exception $e) {
103             wiz_error (trans ('Error when creating data table.'));
104         }
105         wiz_success (trans ('Data table created.'));
106     }
107     if (!is_dir (UPLOADDIR)) {
108         if (file_exists (UPLOADDIR)) {
109             wiz_error (UPLOADDIR . ": " . trans ('exist but is not a directory'));
110         }
111         if (!mkdir (UPLOADDIR)) {
112             wiz_error (UPLOADDIR . ": " . trans ('could not create directory'));
113         } else {
114             wiz_success (UPLOADDIR . ": " . trans ('directory created'));
115         }
116     }
117     if (!is_writeable (UPLOADDIR) || !is_executable (UPLOADDIR)) {
118         wiz_error (UPLOADDIR . ": " . trans ('could not write in directory'));
119     }
120     wiz_success (trans ('SYP is installed. You can now go to <a href="admin.en.php">admin area</a>'));
121 ?>
122
123 </body>
124 </html>