]> dev.renevier.net Git - syp.git/blob - inc/templates_wizard.php
fix broken script in wizard.php
[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       }
19       </script>
20 </head>
21 <body onload="init()">
22
23 <?php
24     function leave () {
25         exit ("\n</body></html>");
26     }
27     function wiz_success ($message) {
28         printf ("<p class=\"success center\">%s</p>", $message);
29     }
30     function wiz_error ($message) {
31         printf ("<p class=\"error center\">%s</p>", $message);
32         leave ();
33     }
34     function wiz_warn ($message) {
35         printf ("<p class=\"warn center\">%s</p>", $message);
36     }
37
38     if (version_compare (PHP_VERSION, '5.0.0', '<')) {
39         wiz_error (trans ("You need at least PHP version 5"));
40     }
41
42     require_once ("./inc/settings.php");
43     require_once ("./inc/db/mysql.php");
44
45     try {
46         $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
47     } catch (Exception $e) {
48         switch ($e->getMessage ()) {
49             case anydbConnection::err_driver_unavailable:
50                 wiz_error ($connection->getdbname() . ': ' . trans ('not supported'));
51             case anydbConnection::err_connection:
52                 wiz_error (trans ('Could not connect to database.'));
53             case anydbConnection::err_unknown_database:
54                 wiz_error (trans ('Database does not exist.'));
55             default:
56                 wiz_error (trans ('Unknown error when connecting to database.'));
57         }
58     }
59     try {
60         $users_table_exists = $connection->users_table_exists ();
61     } catch(Exception $e) {
62         wiz_error (trans ('Unknown error when checking user table.'));
63     }
64
65     if ($users_table_exists) {
66         wiz_success (trans ('Found user table.'));
67     } else {
68         if (isset($_POST ["password"])) {
69             try {
70                 $connection->create_users_table (true);
71             } catch (Exception $e) {
72                 wiz_error (trans ('Error when creating user table.'));
73             }
74             wiz_success (trans ('User table created.'));
75             try {
76                 $connection->setpwd ("admin", $_POST ["password"]);
77             } catch (Exception $e) {
78                 wiz_error (trans ('Error when initializing password.'));
79             }
80             wiz_success (trans ('Admin password initialized.'));
81
82         } else {
83             print ('<form class="center" method="post" action="">
84                     <label for="password">' . trans ("choose admin password") . '</label>
85                     <input id="password" name="password" type="password">
86                     <input type="submit">
87                  </form>');
88             leave ();
89         }
90
91     }
92
93     try {
94         $items_table_exists = $connection->items_table_exists ();
95     } catch (Exception $e) {
96         wiz_error (trans ('Unknown error when checking data table.'));
97     }
98     if ($items_table_exists) {
99         wiz_success (trans ('Found data table.'));
100     } else {
101         try {
102             $connection->create_items_table (true);
103         } catch (Exception $e) {
104             wiz_error (trans ('Error when creating data table.'));
105         }
106         wiz_success (trans ('Data table created.'));
107     }
108     if (!is_dir (UPLOADDIR)) {
109         if (file_exists (UPLOADDIR)) {
110             wiz_error (UPLOADDIR . ": " . trans ('exist but is not a directory'));
111         }
112         if (!mkdir (UPLOADDIR)) {
113             wiz_error (UPLOADDIR . ": " . trans ('could not create directory'));
114         } else {
115             wiz_success (UPLOADDIR . ": " . trans ('directory created'));
116         }
117     }
118     if (!is_writeable (UPLOADDIR) || !is_executable (UPLOADDIR)) {
119         wiz_error (UPLOADDIR . ": " . trans ('could not write in directory'));
120     }
121     wiz_success (trans ('SYP is installed. You can now go to <a href="admin.en.php">admin area</a>'));
122 ?>
123
124 </body>
125 </html>