]> dev.renevier.net Git - syp.git/blob - inc/templates_wizard.php
b6780258d5b7976c34e50eb1f0bdf19c270ccf4e
[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 lang="<?php echo $lang?>">
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
25     if (version_compare (PHP_VERSION, '5.0.0', '<')) {
26         par_error (trans ("You need at least PHP version 5"));
27     }
28
29     require_once ("./inc/settings.php");
30     require_once ("./inc/db/mysql.php");
31     require_once ("./inc/utils.php");
32
33     try {
34         $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
35     } catch (Exception $e) {
36         switch ($e->getMessage ()) {
37             case anydbConnection::err_driver_unavailable:
38                 par_error ($connection->getdbname() . ': ' . trans ('not supported'));
39             case anydbConnection::err_connection:
40                 par_error (trans ('Could not connect to database.'));
41             case anydbConnection::err_unknown_database:
42                 par_error (trans ('Database does not exist.'));
43             default:
44                 par_error (trans ('Unknown error when connecting to database.'));
45         }
46     }
47     try {
48         $users_table_exists = $connection->users_table_exists ();
49     } catch(Exception $e) {
50         par_error (trans ('Unknown error when checking user table.'));
51     }
52
53     if ($users_table_exists) {
54         par_success (trans ('Found user table.'));
55     } else {
56         if (isset($_POST ["password"])) {
57             try {
58                 $connection->create_users_table (true);
59             } catch (Exception $e) {
60                 par_error (trans ('Error when creating user table.'));
61             }
62             par_success (trans ('User table created.'));
63             try {
64                 $connection->setpwd ("admin", $_POST ["password"]);
65             } catch (Exception $e) {
66                 par_error (trans ('Error when initializing password.'));
67             }
68             par_success (trans ('Admin password initialized.'));
69
70         } else {
71             print ('<form class="center" method="post" action="">
72                     <label for="password">' . trans ("choose admin password") . '</label>
73                     <input id="password" name="password" type="password">
74                     <input type="submit">
75                  </form>');
76             leave ();
77         }
78
79     }
80
81     try {
82         $items_table_exists = $connection->items_table_exists ();
83     } catch (Exception $e) {
84         par_error (trans ('Unknown error when checking data table.'));
85     }
86     if ($items_table_exists) {
87         par_success (trans ('Found data table.'));
88     } else {
89         try {
90             $connection->create_items_table (true);
91         } catch (Exception $e) {
92             par_error (trans ('Error when creating data table.'));
93         }
94         par_success (trans ('Data table created.'));
95     }
96
97     safe_create_writable_dir (UPLOADDIR);
98     safe_create_writable_dir (getthumbsdir ());
99
100     if (!function_exists ("gd_info")) {
101         par_warn (trans ('It looks like GD extension is not installed.'));
102     }
103
104     par_success (trans ('SYP is installed. You can now go to <a href="admin.en.php">admin area</a>'));
105 ?>
106
107 </body>
108 </html>